OLD | NEW |
| (Empty) |
1 This directory contains the Ruby extension that implements Protocol Buffers | |
2 functionality in Ruby. | |
3 | |
4 The Ruby extension makes use of generated Ruby code that defines message and | |
5 enum types in a Ruby DSL. You may write definitions in this DSL directly, but | |
6 we recommend using protoc's Ruby generation support with .proto files. The | |
7 build process in this directory only installs the extension; you need to | |
8 install protoc as well to have Ruby code generation functionality. | |
9 | |
10 Installation from Gem | |
11 --------------------- | |
12 | |
13 When we release a version of Protocol Buffers, we will upload a Gem to | |
14 [RubyGems](https://www.rubygems.org/). To use this pre-packaged gem, simply | |
15 install it as you would any other gem: | |
16 | |
17 $ gem install [--prerelease] google-protobuf | |
18 | |
19 The `--pre` flag is necessary if we have not yet made a non-alpha/beta release | |
20 of the Ruby extension; it allows `gem` to consider these "pre-release" | |
21 alpha/beta versions. | |
22 | |
23 Once the gem is installed, you may or may not need `protoc`. If you write your | |
24 message type descriptions directly in the Ruby DSL, you do not need it. | |
25 However, if you wish to generate the Ruby DSL from a `.proto` file, you will | |
26 also want to install Protocol Buffers itself, as described in this repository's | |
27 main `README` file. The version of `protoc` included in the latest release | |
28 supports the `--ruby_out` option to generate Ruby code. | |
29 | |
30 A simple example of using the Ruby extension follows. More extensive | |
31 documentation may be found in the RubyDoc comments (`call-seq` tags) in the | |
32 source, and we plan to release separate, more detailed, documentation at a | |
33 later date. | |
34 | |
35 require 'google/protobuf' | |
36 | |
37 # generated from my_proto_types.proto with protoc: | |
38 # $ protoc --ruby_out=. my_proto_types.proto | |
39 require 'my_proto_types' | |
40 | |
41 mymessage = MyTestMessage.new(:field1 => 42, :field2 => ["a", "b", "c"]) | |
42 mymessage.field1 = 43 | |
43 mymessage.field2.push("d") | |
44 mymessage.field3 = SubMessage.new(:foo => 100) | |
45 | |
46 encoded_data = MyTestMessage.encode(mymessage) | |
47 decoded = MyTestMessage.decode(encoded_data) | |
48 assert decoded == mymessage | |
49 | |
50 puts "JSON:" | |
51 puts MyTestMessage.encode_json(mymessage) | |
52 | |
53 Installation from Source (Building Gem) | |
54 --------------------------------------- | |
55 | |
56 To build this Ruby extension, you will need: | |
57 | |
58 * Rake | |
59 * Bundler | |
60 * Ruby development headers | |
61 * a C compiler | |
62 | |
63 To Build the JRuby extension, you will need: | |
64 | |
65 * Maven | |
66 * The latest version of the protobuf java library (see ../java/README.md) | |
67 * Install JRuby via rbenv or RVM | |
68 | |
69 First switch to the desired platform with rbenv or RVM. | |
70 | |
71 Then install the required Ruby gems: | |
72 | |
73 $ gem install bundler | |
74 $ bundle | |
75 | |
76 Then build the Gem: | |
77 | |
78 $ rake | |
79 $ rake clobber_package gem | |
80 $ gem install `ls pkg/google-protobuf-*.gem` | |
81 | |
82 To run the specs: | |
83 | |
84 $ rake test | |
85 | |
86 This gem includes the upb parsing and serialization library as a single-file | |
87 amalgamation. It is up-to-date with upb git commit | |
88 `535bc2fe2f2b467f59347ffc9449e11e47791257`. | |
89 | |
90 Version Number Scheme | |
91 --------------------- | |
92 | |
93 We are using a version number scheme that is a hybrid of Protocol Buffers' | |
94 overall version number and some Ruby-specific rules. Gem does not allow | |
95 re-uploads of a gem with the same version number, so we add a sequence number | |
96 ("upload version") to the version. We also format alphabetical tags (alpha, | |
97 pre, ...) slightly differently, and we avoid hyphens. In more detail: | |
98 | |
99 * First, we determine the prefix: a Protocol Buffers version "3.0.0-alpha-2" | |
100 becomes "3.0.0.alpha.2". When we release 3.0.0, this prefix will be simply | |
101 "3.0.0". | |
102 * We then append the upload version: "3.0.0.alpha.2.0" or "3.0.0.0". If we need | |
103 to upload a new version of the gem to fix an issue, the version becomes | |
104 "3.0.0.alpha.2.1" or "3.0.0.1". | |
105 * If we are working on a prerelease version, we append a prerelease tag: | |
106 "3.0.0.alpha.3.0.pre". The prerelease tag comes at the end so that when | |
107 version numbers are sorted, any prerelease builds are ordered between the | |
108 prior version and current version. | |
109 | |
110 These rules are designed to work with the sorting rules for | |
111 [Gem::Version](http://ruby-doc.org/stdlib-2.0/libdoc/rubygems/rdoc/Gem/Version.h
tml): | |
112 release numbers should sort in actual release order. | |
OLD | NEW |