json_pure 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ 2010-03-11 (1.2.3)
2
+ * Added a State#[] method which returns an attribute's value in order to
3
+ increase duck type compatibility to Hash.
1
4
  2010-02-27 (1.2.2)
2
5
  * Made some changes to make the building of the parser/generator compatible
3
6
  to Rubinius.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.2
1
+ 1.2.3
@@ -41,7 +41,8 @@ static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject,
41
41
 
42
42
  static ID i_to_s, i_to_json, i_new, i_indent, i_space, i_space_before,
43
43
  i_object_nl, i_array_nl, i_check_circular, i_max_nesting,
44
- i_allow_nan, i_pack, i_unpack, i_create_id, i_extend, i_key_p;
44
+ i_allow_nan, i_pack, i_unpack, i_create_id, i_extend, i_key_p,
45
+ i_aref, i_send, i_respond_to_p;
45
46
 
46
47
  typedef struct JSON_Generator_StateStruct {
47
48
  VALUE indent;
@@ -584,6 +585,20 @@ static VALUE cState_to_h(VALUE self)
584
585
  return result;
585
586
  }
586
587
 
588
+ /*
589
+ * call-seq: [](name)
590
+ *
591
+ * Return the value returned by method +name+.
592
+ */
593
+ static VALUE cState_aref(VALUE self, VALUE name)
594
+ {
595
+ GET_STATE(self);
596
+ if (RTEST(rb_funcall(self, i_respond_to_p, 1, name))) {
597
+ return rb_funcall(self, i_send, 1, name);
598
+ } else {
599
+ return Qnil;
600
+ }
601
+ }
587
602
 
588
603
  /*
589
604
  * call-seq: new(opts = {})
@@ -884,6 +899,7 @@ void Init_generator()
884
899
  rb_define_method(cState, "forget", cState_forget, 1);
885
900
  rb_define_method(cState, "configure", cState_configure, 1);
886
901
  rb_define_method(cState, "to_h", cState_to_h, 0);
902
+ rb_define_method(cState, "[]", cState_aref, 1);
887
903
 
888
904
  mGeneratorMethods = rb_define_module_under(mGenerator, "GeneratorMethods");
889
905
  mObject = rb_define_module_under(mGeneratorMethods, "Object");
@@ -926,6 +942,9 @@ void Init_generator()
926
942
  i_create_id = rb_intern("create_id");
927
943
  i_extend = rb_intern("extend");
928
944
  i_key_p = rb_intern("key?");
945
+ i_aref = rb_intern("[]");
946
+ i_send = rb_intern("__send__");
947
+ i_respond_to_p = rb_intern("respond_to?");
929
948
  #ifdef HAVE_RUBY_ENCODING_H
930
949
  mEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
931
950
  i_encoding = rb_intern("encoding");
@@ -217,6 +217,11 @@ module JSON
217
217
  end
218
218
  result
219
219
  end
220
+
221
+ # Return the value returned by method +name+.
222
+ def [](name)
223
+ __send__ name
224
+ end
220
225
  end
221
226
 
222
227
  module GeneratorMethods
data/lib/json/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module JSON
2
2
  # JSON version
3
- VERSION = '1.2.2'
3
+ VERSION = '1.2.3'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -88,13 +88,15 @@ EOT
88
88
  json = generate({1=>2}, nil)
89
89
  assert_equal('{"1":2}', json)
90
90
  s = JSON.state.new(:check_circular => true)
91
- #assert s.check_circular
91
+ assert s.check_circular?
92
+ assert s[:check_circular?]
92
93
  h = { 1=>2 }
93
94
  h[3] = h
94
95
  assert_raises(JSON::CircularDatastructure) { generate(h) }
95
96
  assert_raises(JSON::CircularDatastructure) { generate(h, s) }
96
97
  s = JSON.state.new(:check_circular => true)
97
- #assert s.check_circular
98
+ assert s.check_circular?
99
+ assert s[:check_circular?]
98
100
  a = [ 1, 2 ]
99
101
  a << a
100
102
  assert_raises(JSON::CircularDatastructure) { generate(a, s) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_pure
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-28 00:00:00 +01:00
12
+ date: 2010-03-11 00:00:00 +01:00
13
13
  default_executable: edit_json.rb
14
14
  dependencies: []
15
15