capn_proto 0.0.1.alpha.3 → 0.0.1.alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml CHANGED
@@ -16,5 +16,4 @@ before_install:
16
16
  --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
17
17
  --slave /usr/bin/gcov gcov /usr/bin/gcov-4.8
18
18
  - sudo update-alternatives --quiet --set gcc /usr/bin/gcc-4.8
19
- - wget https://github.com/kentonv/capnproto/archive/master.zip && unzip master.zip && cd capnproto-master/c++ && ./setup-autotools.sh && autoreconf -i && ./configure && make -j6 check && sudo make install && sudo ldconfig && cd ../..
20
- - export CXXFLAGS="-std=c++11"
19
+ - git clone --depth=1 https://github.com/kentonv/capnproto.git && cd capnproto/c++ && ./setup-autotools.sh && autoreconf -i && ./configure && make -j6 check && sudo make install && sudo ldconfig && cd ../..
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  This here is a [Ruby][ruby] wrapper for the official C++ implementation of [Cap'n Proto][capnp].
8
8
 
9
- [![Build Status](https://travis-ci.org/cstrahan/capnp-ruby.png?branch=master)](https://travis-ci.org/cstrahan/capnp-ruby)
9
+ [![Build Status][travis-badge]][travis-link]
10
10
 
11
11
  # Installing
12
12
 
@@ -16,12 +16,10 @@ First [install libcapnp][libcapnp-install], then install the gem:
16
16
  gem install capn_proto --pre
17
17
  ```
18
18
 
19
- Remember to set the `CXX` and `CXXFLAGS` environment variables as necessary. As an OSX user, having followed the [instructions for installing libcapnp on OSX][libcapnp-install], the correct incantation is as follows:
19
+ The native extension for this gem requires a C++ compiler with C++11 features, so use the same C++ compiler and flags that you used to compile libcapnp (e.g. `CXX` and `CXXFLAGS`). As an OSX user, having followed the [instructions for installing libcapnp on OSX][libcapnp-install], the correct incantation is as follows:
20
20
 
21
21
  ```bash
22
- export CXX=$HOME/clang-3.2/bin/clang++
23
- export CXXFLAGS="-std=c++11 -stdlib=libc++"
24
- gem install capn_proto --pre
22
+ CXX=$HOME/clang-3.2/bin/clang++ gem install capn_proto --pre
25
23
  ```
26
24
 
27
25
  # Example
@@ -78,3 +76,6 @@ Proper support for [JRuby][jruby] will come after I implement support for Java.
78
76
  [jruby]: http://jruby.org/ "JRuby"
79
77
  [libcapnp-install]: http://kentonv.github.io/capnproto/install.html "Installing Cap'n Proto"
80
78
  [mit-license]: http://opensource.org/licenses/MIT "MIT License"
79
+
80
+ [travis-link]: https://travis-ci.org/cstrahan/capnp-ruby
81
+ [travis-badge]: https://travis-ci.org/cstrahan/capnp-ruby.png?branch=master
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ require 'capn_proto/version'
1
2
  GEMSPEC = eval(File.read('capn_proto.gemspec'))
2
3
 
3
4
  require 'rubygems/package_task'
@@ -17,9 +18,23 @@ end
17
18
 
18
19
  task :default => [:compile, :spec]
19
20
 
21
+ Rake::Task["clean"].clear
22
+ task :clean do
23
+ rm_r "tmp" rescue nil
24
+ rm "lib/capn_proto/capn_proto.bundle" rescue nil
25
+ end
26
+
27
+ task :release => [:clean, :compile, :spec, :gem] do
28
+ tag = "v#{CapnProto::VERSION}"
29
+ sh "git tag #{tag}"
30
+ sh "git push origin #{tag}"
31
+ sh "gem push pkg/capn_proto-#{CapnProto::VERSION}.gem"
32
+ end
33
+
20
34
  task :console do
21
35
  $: << File.expand_path("../lib", __FILE__)
22
36
  require 'irb'
37
+ require 'capn_proto'
23
38
  ARGV.clear
24
39
  IRB.start
25
40
  end
@@ -0,0 +1,126 @@
1
+ require 'shellwords'
2
+ require 'tmpdir'
3
+
4
+ # Discovers support for C++11 features,
5
+ # and any required CXXFLAGS for such features.
6
+ class CXXCompiler
7
+ CXX_COMPILER_FEATURES = <<-CODE
8
+ template <typename T>
9
+ struct check
10
+ {
11
+ static_assert(sizeof(int) <= sizeof(T), "not big enough");
12
+ };
13
+
14
+ typedef check<check<bool>> right_angle_brackets;
15
+
16
+ int a;
17
+ decltype(a) b;
18
+
19
+ typedef check<int> check_type;
20
+ check_type c;
21
+ check_type&& cr = static_cast<check_type&&>(c);
22
+
23
+ #ifdef __has_include
24
+ #if __has_include(<type_traits>)
25
+ #include <type_traits>
26
+ #endif
27
+ #endif
28
+ CODE
29
+
30
+ CXX_LIBRARY_FEATURES = <<-CODE
31
+ #include <initializer_list>
32
+ #include <unordered_map>
33
+ #include <atomic>
34
+ #include <thread>
35
+ CODE
36
+
37
+ # env: The environment variables (e.g. CXX, CXXFLAGS).
38
+ def initialize(env)
39
+ @env = env.dup
40
+ @exist = system("command -v #{@env['CXX'].shellescape} >/dev/null 2>&1")
41
+ end
42
+
43
+ # True if the compiler is accessible on the $PATH.
44
+ def exist?
45
+ @exist
46
+ end
47
+
48
+ # True if support for C++11 was detected, false otherwise.
49
+ def has_cxx11_compiler_support?
50
+ !!std_flag
51
+ end
52
+
53
+ # True if support for C++11 libraries was detected, false otherwise.
54
+ def has_cxx11_library_support?
55
+ !!stdlib_flag
56
+ end
57
+
58
+ # The required std flag (e.g. '-std=c++11'),
59
+ # empty string if unecessary given the current environment and/or compiler,
60
+ # or nil in the case where the compiler has no support.
61
+ def std_flag
62
+ test_compiler_flags(@env)
63
+ @std_flag
64
+ end
65
+
66
+ # The required stdlib flag (e.g. '-stdlib=libc++'),
67
+ # empty string if unecessary given the current environment and/or compiler,
68
+ # or nil in the case where the compiler has no support.
69
+ def stdlib_flag
70
+ test_compiler_flags(@env)
71
+ @stdlib_flag
72
+ end
73
+
74
+ private
75
+
76
+ # Detect any required flags.
77
+ def test_compiler_flags(env)
78
+ return if @tested || !exist?
79
+ @tested = true
80
+
81
+ cxxflags = (env['CXXFLAGS'] || '')
82
+ env = env.dup
83
+
84
+ flags = ['', '-std=gnu++11', '-std=gnu++0x', '-std=c++11', '-std=c++0x']
85
+ @std_flag = flags.detect do |flag|
86
+ env['CXXFLAGS'] = [cxxflags, flag].join(' ')
87
+ compile(CXX_COMPILER_FEATURES, env)
88
+ end
89
+
90
+ return unless @std_flag
91
+
92
+ env = env.dup
93
+ flags = ['', '-stdlib=libc++']
94
+ @stdlib_flag = flags.detect do |flag|
95
+ env['CXXFLAGS'] = [cxxflags, std_flag, flag].join(' ')
96
+ compile(CXX_LIBRARY_FEATURES, env)
97
+ end
98
+ end
99
+
100
+ # Compile a snippet of C++, returning true or false to indicate
101
+ # success.
102
+ def compile(code, env)
103
+ Dir.mktmpdir do |dir|
104
+ Dir.chdir(dir) do
105
+ File.open("test.cc", "w") {|f| f.write(code)}
106
+ system("#{env['CXX'].shellescape} #{env['CXXFLAGS']} -c test.cc >/dev/null 2>&1")
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ if $0 == __FILE__
113
+ compiler = CXXCompiler.new(ENV.to_hash)
114
+ cxx = ENV['CXX']
115
+ cxxflags = ENV['CXXFLAGS']
116
+ extra_cxxflags = [compiler.std_flag, compiler.stdlib_flag].join(' ')
117
+ compiler_support = compiler.has_cxx11_compiler_support? ? 'YES' : 'NO'
118
+ lib_support = compiler.has_cxx11_library_support? ? 'YES' : 'NO'
119
+
120
+ puts " given CXX = #{cxx}"
121
+ puts " given CXXFLAGS = #{cxxflags}"
122
+ puts "additional CXXFLAGS = #{extra_cxxflags}"
123
+ puts ""
124
+ puts "Has C++11 compiler support? #{compiler_support}"
125
+ puts "Has C++11 library support? #{lib_support}"
126
+ end
@@ -35,6 +35,8 @@ namespace ruby_capn_proto {
35
35
  WrappedType* wrapped = unwrap(rb_obj);
36
36
  *wrapped = kj::mv(reader);
37
37
 
38
+ rb_iv_set(rb_obj, "parent", parent);
39
+
38
40
  return rb_obj;
39
41
  }
40
42
 
@@ -0,0 +1,56 @@
1
+ #include "ruby_capn_proto.h"
2
+ #include "dynamic_object_reader.h"
3
+ #include "dynamic_struct_reader.h"
4
+ #include "struct_schema.h"
5
+ #include "class_builder.h"
6
+ #include "util.h"
7
+
8
+ namespace ruby_capn_proto {
9
+ using WrappedType = capnp::ObjectPointer::Reader;
10
+ VALUE DynamicObjectReader::Class;
11
+
12
+ void DynamicObjectReader::Init() {
13
+ ClassBuilder("DynamicObjectReader", rb_cObject).
14
+ defineAlloc(&alloc).
15
+ defineMethod("as_struct", &as_struct).
16
+ store(&Class);
17
+ }
18
+
19
+ void DynamicObjectReader::free(WrappedType* p) {
20
+ p->~Reader();
21
+ ruby_xfree(p);
22
+ }
23
+
24
+ VALUE DynamicObjectReader::alloc(VALUE klass) {
25
+ return Data_Wrap_Struct(klass, NULL, free, ruby_xmalloc(sizeof(WrappedType)));
26
+ }
27
+
28
+ WrappedType* DynamicObjectReader::unwrap(VALUE self) {
29
+ WrappedType* p;
30
+ Data_Get_Struct(self, WrappedType, p);
31
+ return p;
32
+ }
33
+
34
+ VALUE DynamicObjectReader::create(WrappedType reader, VALUE parent) {
35
+ VALUE rb_obj = alloc(Class);
36
+ WrappedType* wrapped = unwrap(rb_obj);
37
+ *wrapped = kj::mv(reader);
38
+
39
+ rb_iv_set(rb_obj, "parent", parent);
40
+
41
+ return rb_obj;
42
+ }
43
+
44
+ VALUE DynamicObjectReader::as_struct(VALUE self, VALUE rb_schema) {
45
+ if (rb_respond_to(rb_schema, rb_intern("schema"))) {
46
+ rb_schema = rb_funcall(rb_schema, rb_intern("schema"), 0);
47
+ }
48
+
49
+ auto reader = *unwrap(self);
50
+ auto schema = *StructSchema::unwrap(rb_schema);
51
+
52
+ return DynamicStructReader::create(
53
+ reader.getAs<capnp::DynamicStruct>(schema),
54
+ self);
55
+ }
56
+ }
@@ -0,0 +1,22 @@
1
+ #ifndef DYNAMIC_OBJECT_READER_H
2
+ #define DYNAMIC_OBJECT_READER_H
3
+
4
+ #include "ruby_capn_proto.h"
5
+
6
+ namespace ruby_capn_proto {
7
+ class DynamicObjectReader {
8
+ public:
9
+ using WrappedType = capnp::ObjectPointer::Reader;
10
+ static void Init();
11
+ static VALUE alloc(VALUE klass);
12
+ static VALUE create(WrappedType reader, VALUE parent);
13
+ static void free(WrappedType* p);
14
+ static WrappedType* unwrap(VALUE self);
15
+ static VALUE as_struct(VALUE self, VALUE name);
16
+
17
+ static VALUE Class;
18
+ };
19
+ }
20
+
21
+
22
+ #endif /* DYNAMIC_STRUCT_READER_H */
@@ -31,11 +31,13 @@ namespace ruby_capn_proto {
31
31
  return p;
32
32
  }
33
33
 
34
- VALUE DynamicStructReader::create(WrappedType reader) {
34
+ VALUE DynamicStructReader::create(WrappedType reader, VALUE parent) {
35
35
  VALUE rb_obj = alloc(Class);
36
36
  WrappedType* wrapped = unwrap(rb_obj);
37
37
  *wrapped = kj::mv(reader);
38
38
 
39
+ rb_iv_set(rb_obj, "parent", parent);
40
+
39
41
  return rb_obj;
40
42
  }
41
43
 
@@ -9,7 +9,7 @@ namespace ruby_capn_proto {
9
9
  using WrappedType = capnp::DynamicStruct::Reader;
10
10
  static void Init();
11
11
  static VALUE alloc(VALUE klass);
12
- static VALUE create(WrappedType reader);
12
+ static VALUE create(WrappedType reader, VALUE parent);
13
13
  static void free(WrappedType* p);
14
14
  static WrappedType* unwrap(VALUE self);
15
15
  static VALUE which(VALUE self);
@@ -2,6 +2,7 @@
2
2
  #include "dynamic_value_reader.h"
3
3
  #include "dynamic_list_reader.h"
4
4
  #include "dynamic_struct_reader.h"
5
+ #include "dynamic_object_reader.h"
5
6
 
6
7
  namespace ruby_capn_proto {
7
8
  VALUE DynamicValueReader::to_ruby(capnp::DynamicValue::Reader value, VALUE parent) {
@@ -10,9 +11,9 @@ namespace ruby_capn_proto {
10
11
  case capnp::DynamicValue::BOOL:
11
12
  return value.as<bool>() ? Qtrue : Qfalse;
12
13
  case capnp::DynamicValue::INT:
13
- return INT2FIX(value.as<int64_t>());
14
+ return INT2NUM(value.as<int64_t>());
14
15
  case capnp::DynamicValue::UINT:
15
- return INT2FIX(value.as<uint64_t>());
16
+ return UINT2NUM(value.as<uint64_t>());
16
17
  case capnp::DynamicValue::FLOAT:
17
18
  return rb_float_new(value.as<double>());
18
19
  case capnp::DynamicValue::TEXT:
@@ -28,7 +29,7 @@ namespace ruby_capn_proto {
28
29
  case capnp::DynamicValue::LIST:
29
30
  return DynamicListReader::create(value.as<capnp::DynamicList>(), parent);
30
31
  case capnp::DynamicValue::STRUCT:
31
- return DynamicStructReader::create(value.as<capnp::DynamicStruct>());
32
+ return DynamicStructReader::create(value.as<capnp::DynamicStruct>(), parent);
32
33
  case capnp::DynamicValue::ENUM:
33
34
  {
34
35
  auto enumerant_maybe = value.as<capnp::DynamicEnum>().getEnumerant();
@@ -39,6 +40,8 @@ namespace ruby_capn_proto {
39
40
  return Qnil;
40
41
  }
41
42
  }
43
+ case capnp::DynamicValue::OBJECT:
44
+ return DynamicObjectReader::create(value.as<capnp::ObjectPointer>(), parent);
42
45
  case capnp::DynamicValue::VOID:
43
46
  return Qnil;
44
47
  case capnp::DynamicValue::UNKNOWN:
@@ -1,4 +1,18 @@
1
1
  require 'mkmf'
2
+ require File.expand_path("../cxx_compiler", __FILE__)
3
+
4
+ compiler = CXXCompiler.new({'CXX' => CONFIG['CXX']}.merge(ENV.to_hash))
5
+ unless compiler.has_cxx11_compiler_support?
6
+ abort "*** A compiler with support for C++11 language features is required."
7
+ end
8
+ unless compiler.has_cxx11_library_support?
9
+ abort "*** A C++ library with support for C++11 features is required."
10
+ end
11
+
12
+ CONFIG['CXX'] = ENV['CXX'] || CONFIG['CXX']
13
+ CONFIG['CXXFLAGS'] = [(ENV['CXXFLAGS'] || CONFIG['CXXFLAGS']),
14
+ compiler.std_flag,
15
+ compiler.stdlib_flag].join(' ')
2
16
 
3
17
  if enable_config('debug')
4
18
  CONFIG['CFLAGS'] += " -O0 -ggdb3"
@@ -6,24 +20,8 @@ else
6
20
  $CPPFLAGS += " -DNDEBUG"
7
21
  end
8
22
 
9
- CONFIG['CXX'] = ENV['CXX'] if ENV['CXX']
10
- CONFIG['CXXFLAGS'] += " #{ENV['CXXFLAGS']}" if ENV['CXXFLAGS']
11
-
12
23
  $LDFLAGS += " -lcapnpc"
13
24
  $LDFLAGS += " -lcapnp"
14
25
  $LDFLAGS += " -lkj"
15
26
 
16
27
  create_makefile('capn_proto/capn_proto')
17
-
18
- # HACK ATTACK
19
- # def inreplace(path, search, replace)
20
- # contents = File.read(path)
21
- # contents.gsub!(search, replace)
22
- # File.open(path, "w") do |f|
23
- # f.write(contents)
24
- # end
25
- # end
26
-
27
- # inreplace("Makefile", "V = 0", "V = 1")
28
- # inreplace("Makefile", "-O3", "-O0")
29
- # inreplace("Makefile", "ECHO = $(ECHO1:0=@echo)", "ECHO = @echo")
@@ -8,6 +8,7 @@
8
8
  #include "dynamic_struct_reader.h"
9
9
  #include "dynamic_list_reader.h"
10
10
  #include "stream_fd_message_reader.h"
11
+ #include "dynamic_object_reader.h"
11
12
  #include "message_reader.h"
12
13
  #include "field_list.h"
13
14
 
@@ -30,5 +31,6 @@ extern "C" {
30
31
  DynamicListReader::Init();
31
32
  StreamFdMessageReader::Init();
32
33
  FieldList::Init();
34
+ DynamicObjectReader::Init();
33
35
  }
34
36
  }
@@ -31,10 +31,13 @@ namespace ruby_capn_proto {
31
31
  return p;
32
32
  }
33
33
 
34
- VALUE ListNestedNodeReader::create(NodeList schema) {
34
+ VALUE ListNestedNodeReader::create(NodeList schema, VALUE parent) {
35
35
  VALUE rb_obj = alloc(Class);
36
36
  NodeList* wrapped_schema = unwrap(rb_obj);
37
37
  *wrapped_schema = kj::mv(schema);
38
+
39
+ rb_iv_set(rb_obj, "parent", parent);
40
+
38
41
  return rb_obj;
39
42
  }
40
43
 
@@ -13,7 +13,7 @@ namespace ruby_capn_proto {
13
13
  static VALUE alloc(VALUE klass);
14
14
  static void free(NodeList* p);
15
15
  static NodeList* unwrap(VALUE self);
16
- static VALUE create(NodeList reader);
16
+ static VALUE create(NodeList reader, VALUE parent);
17
17
  static VALUE size(VALUE self);
18
18
  static VALUE get(VALUE self, VALUE index);
19
19
 
@@ -33,7 +33,7 @@ namespace ruby_capn_proto {
33
33
  return p;
34
34
  }
35
35
 
36
- VALUE ParsedSchema::create(VALUE parent, WrappedType schema) {
36
+ VALUE ParsedSchema::create(WrappedType schema, VALUE parent) {
37
37
  VALUE rb_obj = alloc(Class);
38
38
  WrappedType* wrapped_schema = unwrap(rb_obj);
39
39
  *wrapped_schema = kj::mv(schema);
@@ -44,15 +44,15 @@ namespace ruby_capn_proto {
44
44
  }
45
45
 
46
46
  VALUE ParsedSchema::get_proto(VALUE self) {
47
- return SchemaNodeReader::create(unwrap(self)->getProto());
47
+ return SchemaNodeReader::create(unwrap(self)->getProto(), self);
48
48
  }
49
49
 
50
50
  VALUE ParsedSchema::get_nested(VALUE self, VALUE rb_name) {
51
51
  auto name = Util::toString(rb_name);
52
- return create(self, unwrap(self)->getNested(name));
52
+ return create(unwrap(self)->getNested(name), self);
53
53
  }
54
54
 
55
55
  VALUE ParsedSchema::as_struct(VALUE self) {
56
- return StructSchema::create(unwrap(self)->asStruct());
56
+ return StructSchema::create(unwrap(self)->asStruct(), self);
57
57
  }
58
58
  }
@@ -9,7 +9,7 @@ namespace ruby_capn_proto {
9
9
  using WrappedType = capnp::ParsedSchema;
10
10
  static void Init();
11
11
  static VALUE alloc(VALUE klass);
12
- static VALUE create(VALUE parent, WrappedType schema);
12
+ static VALUE create(WrappedType schema, VALUE parent);
13
13
  static void free(WrappedType* p);
14
14
  static WrappedType* unwrap(VALUE self);
15
15
  static VALUE get_proto(VALUE self);
@@ -14,6 +14,7 @@
14
14
  #include <capnp/schema.h>
15
15
  #include <capnp/message.h>
16
16
  #include <capnp/dynamic.h>
17
+ #include <capnp/object.h>
17
18
 
18
19
  #include <ruby.h>
19
20
  #ifdef __
@@ -19,10 +19,13 @@ namespace ruby_capn_proto {
19
19
  return Data_Wrap_Struct(klass, NULL, free, ruby_xmalloc(sizeof(WrappedType)));
20
20
  }
21
21
 
22
- VALUE SchemaNodeReader::create(WrappedType reader) {
22
+ VALUE SchemaNodeReader::create(WrappedType reader, VALUE parent) {
23
23
  VALUE rb_obj = alloc(Class);
24
24
  WrappedType* wrapped = unwrap(rb_obj);
25
25
  *wrapped = kj::mv(reader);
26
+
27
+ rb_iv_set(rb_obj, "parent", parent);
28
+
26
29
  return rb_obj;
27
30
  }
28
31
 
@@ -38,7 +41,7 @@ namespace ruby_capn_proto {
38
41
  }
39
42
 
40
43
  VALUE SchemaNodeReader::get_nested_nodes(VALUE self) {
41
- return ListNestedNodeReader::create(unwrap(self)->getNestedNodes());
44
+ return ListNestedNodeReader::create(unwrap(self)->getNestedNodes(), self);
42
45
  }
43
46
 
44
47
  VALUE SchemaNodeReader::is_struct(VALUE self) {
@@ -8,7 +8,7 @@ namespace ruby_capn_proto {
8
8
  public:
9
9
  static void Init();
10
10
  static VALUE alloc(VALUE klass);
11
- static VALUE create(capnp::schema::Node::Reader reader);
11
+ static VALUE create(capnp::schema::Node::Reader reader, VALUE parent);
12
12
  static void free(capnp::schema::Node::Reader* p);
13
13
  static capnp::schema::Node::Reader* unwrap(VALUE self);
14
14
  static VALUE get_nested_nodes(VALUE self);
@@ -48,6 +48,6 @@ namespace ruby_capn_proto {
48
48
  StringValueCStr(rb_disk_path),
49
49
  importsPtrs
50
50
  );
51
- return ParsedSchema::create(self, schema);
51
+ return ParsedSchema::create(schema, self);
52
52
  }
53
53
  }
@@ -48,6 +48,6 @@ namespace ruby_capn_proto {
48
48
 
49
49
  auto schema = *StructSchema::unwrap(rb_schema);
50
50
  auto reader = unwrap(self)->getRoot<capnp::DynamicStruct>(schema);
51
- return DynamicStructReader::create(reader);
51
+ return DynamicStructReader::create(reader, self);
52
52
  }
53
53
  }
@@ -31,11 +31,13 @@ namespace ruby_capn_proto {
31
31
  return p;
32
32
  }
33
33
 
34
- VALUE StructSchema::create(WrappedType schema) {
34
+ VALUE StructSchema::create(WrappedType schema, VALUE parent) {
35
35
  VALUE rb_obj = alloc(Class);
36
36
  WrappedType* wrapped_schema = unwrap(rb_obj);
37
37
  *wrapped_schema = kj::mv(schema);
38
38
 
39
+ rb_iv_set(rb_obj, "parent", parent);
40
+
39
41
  return rb_obj;
40
42
  }
41
43
 
@@ -9,7 +9,7 @@ namespace ruby_capn_proto {
9
9
  using WrappedType = capnp::StructSchema;
10
10
  static void Init();
11
11
  static VALUE alloc(VALUE klass);
12
- static VALUE create(WrappedType schema);
12
+ static VALUE create(WrappedType schema, VALUE parent);
13
13
  static void free(WrappedType* p);
14
14
  static WrappedType* unwrap(VALUE self);
15
15
  static VALUE field_names(VALUE self);
@@ -1,3 +1,3 @@
1
1
  module CapnProto
2
- VERSION = "0.0.1.alpha.3"
2
+ VERSION = "0.0.1.alpha.4"
3
3
  end
data/lib/capn_proto.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  require 'capn_proto/capn_proto'
2
+ require 'capn_proto/version'
2
3
 
3
4
  module CapnProto
4
5
  ListNestedNodeReader.class_eval do
5
6
  include Enumerable
6
7
  def each
8
+ return to_enum(:each) unless block_given?
7
9
  (0...size).each do |n|
8
10
  yield self[n]
9
11
  end
@@ -13,6 +15,7 @@ module CapnProto
13
15
  DynamicListReader.class_eval do
14
16
  include Enumerable
15
17
  def each
18
+ return to_enum(:each) unless block_given?
16
19
  (0...size).each do |n|
17
20
  yield self[n]
18
21
  end
@@ -23,12 +26,6 @@ module CapnProto
23
26
  def method_missing(name, *args, &block)
24
27
  self[name.to_s, *args, &block]
25
28
  end
26
-
27
- def each
28
- (0...size).each do |n|
29
- yield self[n]
30
- end
31
- end
32
29
  end
33
30
 
34
31
  module SchemaLoader
@@ -41,29 +38,29 @@ module CapnProto
41
38
 
42
39
  @schema_parser ||= CapnProto::SchemaParser.new
43
40
 
41
+ load_schema_rec = Proc.new do |schema, mod|
42
+ node = schema.get_proto
43
+ nested_nodes = node.nested_nodes
44
+
45
+ if node.struct?
46
+ struct_schema = schema.as_struct
47
+ mod.instance_variable_set(:@schema, struct_schema)
48
+ mod.extend(Struct)
49
+ end
50
+
51
+ nested_nodes.each do |nested_node|
52
+ nested_mod = mod.const_set(nested_node.name, Module.new)
53
+ nested_schema = schema.get_nested(nested_node.name)
54
+ load_schema_rec.call(nested_schema, nested_mod)
55
+ end
56
+ end
57
+
44
58
  schema = @schema_parser.parse_disk_file(
45
59
  display_name,
46
60
  file_name,
47
61
  imports);
48
62
 
49
- _load_schema_rec(schema, self)
50
- end
51
-
52
- def _load_schema_rec(schema, mod)
53
- node = schema.get_proto
54
- nested_nodes = node.nested_nodes
55
-
56
- if node.struct?
57
- struct_schema = schema.as_struct
58
- mod.instance_variable_set(:@schema, struct_schema)
59
- mod.extend(Struct)
60
- end
61
-
62
- nested_nodes.each do |nested_node|
63
- nested_mod = mod.const_set(nested_node.name, Module.new)
64
- nested_schema = schema.get_nested(nested_node.name)
65
- _load_schema_rec(nested_schema, nested_mod)
66
- end
63
+ load_schema_rec.call(schema, self)
67
64
  end
68
65
 
69
66
  module Struct
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capn_proto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha.3
4
+ version: 0.0.1.alpha.4
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-04 00:00:00.000000000 Z
12
+ date: 2013-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -117,8 +117,11 @@ files:
117
117
  - ext/capn_proto/.ycm_extra_conf.pyc
118
118
  - ext/capn_proto/class_builder.cc
119
119
  - ext/capn_proto/class_builder.h
120
+ - ext/capn_proto/cxx_compiler.rb
120
121
  - ext/capn_proto/dynamic_list_reader.cc
121
122
  - ext/capn_proto/dynamic_list_reader.h
123
+ - ext/capn_proto/dynamic_object_reader.cc
124
+ - ext/capn_proto/dynamic_object_reader.h
122
125
  - ext/capn_proto/dynamic_struct_reader.cc
123
126
  - ext/capn_proto/dynamic_struct_reader.h
124
127
  - ext/capn_proto/dynamic_value_reader.cc
@@ -174,7 +177,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
174
177
  version: '0'
175
178
  segments:
176
179
  - 0
177
- hash: -2636867598034040588
180
+ hash: -525111796228691179
178
181
  required_rubygems_version: !ruby/object:Gem::Requirement
179
182
  none: false
180
183
  requirements: