brianmario-yajl-ruby 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,27 @@
1
+ = Changelog
2
+
3
+ 0.3.0 (April 23rd, 2009)
4
+ * slight refactor of ActiveSupport tests to better reflect how they actually
5
+ exist in ActiveSupport
6
+ * typo correction in the changelog which had the years in 2008
7
+ * added some initial spec tests
8
+ ** ported some from ActiveSupport to ensure proper compatibility
9
+ ** included 57 JSON fixtures to test against, all of which pass
10
+ * changed parser config to not check for invalid unicode characters as Ruby is
11
+ going to do this anyway (?). This resolves the remaining test failures around unicode.
12
+ * changed how the parser was dealing with numbers to prevent overflows
13
+ * added an exception class Yajl::ParseError which is now used in place of simply
14
+ printing to STDERR upon a parsing error
15
+ * renamed a couple of JSON test files in the benchmark folder to better represent their
16
+ contents
17
+ * misc README updates
18
+
19
+ 0.2.1 (April 23rd, 2009)
20
+ * fixed parsing bug - also fixed failing ActiveSupport test failures
21
+ (except for the unicode one, which is an issue in Yajl itself)
22
+
23
+ 0.2.0 (April 22nd, 2009)
24
+ * updated gemspec and README
25
+
26
+ 0.1.0 (April 21st, 2009)
27
+ * initial release - gemified
data/README.rdoc CHANGED
@@ -28,7 +28,13 @@ or maybe STDIN
28
28
 
29
29
  There are a lot more possibilities, some of which I'm going to write other gems/plugins for.
30
30
 
31
- Some ideas are parsing logs in JSON format, an ActiveSupport patch, Rack middleware, use with ohai, JSON API clients, etc...
31
+ Some ideas are:
32
+ * parsing logs in JSON format
33
+ * an ActiveSupport patch (http://github.com/technoweenie/rails/commit/f9abcc93a3660fcf46172c4cd8a2f36ba5a5510d)
34
+ * Rack middleware (ideally the JSON body could be handed to the parser while it's still being received)
35
+ * use with ohai
36
+ * JSON API clients
37
+ * etc...
32
38
 
33
39
  == How to install
34
40
 
@@ -72,4 +78,5 @@ Here's a list of things I need to get done to improve the awesomeness of this li
72
78
 
73
79
  * Write up a test suite
74
80
  * Fix known parsing issues with certain JSON strings (Yajl itself works fine, it's the logic in this library that needs a little tweaking)
75
- * Write more docs
81
+ * Write more docs
82
+ * Change API so it can accept a String or an IO
data/Rakefile CHANGED
@@ -5,8 +5,8 @@ begin
5
5
  gem.summary = "Ruby C bindings to the excellent Yajl JSON stream-based parser library."
6
6
  gem.email = "seniorlopez@gmail.com"
7
7
  gem.homepage = "http://github.com/brianmario/yajl-ruby"
8
- gem.description = "Ruby C bindings to the excellent Yajl JSON stream-based parser library."
9
8
  gem.authors = ["Brian Lopez"]
9
+ gem.require_paths = ["ext"]
10
10
  gem.files.include %w(lib/jeweler/templates/.document lib/jeweler/templates/.gitignore)
11
11
  # gem.rubyforge_project = "yajl-ruby"
12
12
  end
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 1
2
+ :patch: 0
3
3
  :major: 0
4
- :minor: 2
4
+ :minor: 3
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brianmario-yajl-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Lopez
@@ -9,24 +9,23 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-22 00:00:00 -07:00
12
+ date: 2009-04-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: ""
16
+ description:
17
17
  email: seniorlopez@gmail.com
18
18
  executables: []
19
19
 
20
- extensions:
21
- - ext/extconf.rb
22
- extra_rdoc_files: []
20
+ extensions: []
23
21
 
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
24
  files:
25
+ - CHANGELOG.rdoc
25
26
  - README.rdoc
26
27
  - Rakefile
27
28
  - VERSION.yml
28
- - ext/extconf.rb
29
- - ext/yajl.c
30
29
  has_rdoc: true
31
30
  homepage: http://github.com/brianmario/yajl-ruby
32
31
  post_install_message:
data/ext/extconf.rb DELETED
@@ -1,6 +0,0 @@
1
- require 'mkmf'
2
- dir_config('yajl')
3
- have_header('yajl/yajl_parse.h')
4
- have_header('yajl/yajl_gen.h')
5
- have_library('yajl')
6
- create_makefile("yajl")
data/ext/yajl.c DELETED
@@ -1,150 +0,0 @@
1
- #include <yajl/yajl_parse.h>
2
- #include <yajl/yajl_gen.h>
3
- #include <ruby.h>
4
-
5
- void set_static_value(void * ctx, VALUE val) {
6
- VALUE len = RARRAY((VALUE)ctx)->len;
7
-
8
- if (len > 0) {
9
- VALUE lastEntry = rb_ary_entry((VALUE)ctx, len-1);
10
- VALUE hash;
11
- switch (TYPE(lastEntry)) {
12
- case T_ARRAY:
13
- rb_ary_push(lastEntry, val);
14
- if (TYPE(val) == T_HASH || TYPE(val) == T_ARRAY) {
15
- rb_ary_push((VALUE)ctx, val);
16
- }
17
- break;
18
- case T_HASH:
19
- rb_hash_aset(lastEntry, val, Qnil);
20
- rb_ary_push((VALUE)ctx, val);
21
- break;
22
- case T_STRING:
23
- hash = rb_ary_entry((VALUE)ctx, len-2);
24
- if (TYPE(hash) == T_HASH) {
25
- rb_hash_aset(hash, lastEntry, val);
26
- rb_ary_pop((VALUE)ctx);
27
- if (TYPE(val) == T_HASH || TYPE(val) == T_ARRAY) {
28
- rb_ary_push((VALUE)ctx, val);
29
- }
30
- }
31
- break;
32
- }
33
- } else {
34
- rb_ary_push((VALUE)ctx, val);
35
- }
36
- }
37
-
38
- static int found_null(void * ctx) {
39
- set_static_value(ctx, Qnil);
40
- return 1;
41
- }
42
-
43
- static int found_boolean(void * ctx, int boolean) {
44
- set_static_value(ctx, boolean ? Qtrue : Qfalse);
45
- return 1;
46
- }
47
-
48
- static int found_integer(void * ctx, long integerVal) {
49
- set_static_value(ctx, LONG2FIX(integerVal));
50
- return 1;
51
- }
52
-
53
- static int found_double(void * ctx, double doubleVal) {
54
- set_static_value(ctx, rb_float_new(doubleVal));
55
- return 1;
56
- }
57
-
58
- static int found_string(void * ctx, const unsigned char * stringVal, unsigned int stringLen) {
59
- set_static_value(ctx, rb_str_new((char *)stringVal, stringLen));
60
- return 1;
61
- }
62
-
63
- static int found_hash_key(void * ctx, const unsigned char * stringVal, unsigned int stringLen) {
64
- set_static_value(ctx, rb_str_new((char *)stringVal, stringLen));
65
- return 1;
66
- }
67
-
68
- static int found_start_hash(void * ctx) {
69
- set_static_value(ctx, rb_hash_new());
70
- return 1;
71
- }
72
-
73
- static int found_end_hash(void * ctx) {
74
- if (RARRAY((VALUE)ctx)->len > 1) {
75
- rb_ary_pop((VALUE)ctx);
76
- }
77
- return 1;
78
- }
79
-
80
- static int found_start_array(void * ctx) {
81
- set_static_value(ctx, rb_ary_new());
82
- return 1;
83
- }
84
-
85
- static int found_end_array(void * ctx) {
86
- if (RARRAY((VALUE)ctx)->len > 1) {
87
- rb_ary_pop((VALUE)ctx);
88
- }
89
- return 1;
90
- }
91
-
92
- static yajl_callbacks callbacks = {
93
- found_null,
94
- found_boolean,
95
- found_integer,
96
- found_double,
97
- NULL,
98
- found_string,
99
- found_start_hash,
100
- found_hash_key,
101
- found_end_hash,
102
- found_start_array,
103
- found_end_array
104
- };
105
-
106
- ID intern_io_read, intern_eof;
107
- yajl_parser_config cfg = {1, 1};
108
-
109
- static VALUE t_parse(VALUE self, VALUE io) {
110
- yajl_handle hand;
111
- yajl_status stat;
112
- int bufferSize = 8192;
113
- intern_io_read = rb_intern("read");
114
- intern_eof = rb_intern("eof?");
115
- VALUE ctx = rb_ary_new();
116
-
117
- // allocate our parser
118
- hand = yajl_alloc(&callbacks, &cfg, NULL, (void *)ctx);
119
- VALUE parsed = rb_str_new("", 0);
120
- VALUE rbufsize = INT2FIX(bufferSize);
121
-
122
- // now parse from the IO
123
- while (rb_funcall(io, intern_eof, 0) == Qfalse) {
124
- rb_funcall(io, intern_io_read, 2, rbufsize, parsed);
125
-
126
- stat = yajl_parse(hand, (const unsigned char *)RSTRING(parsed)->ptr, RSTRING(parsed)->len);
127
-
128
- if (stat != yajl_status_ok && stat != yajl_status_insufficient_data) {
129
- unsigned char * str = yajl_get_error(hand, 1, (const unsigned char *)RSTRING_PTR(parsed), RSTRING_LEN(parsed));
130
- fprintf(stderr, (const char *) str);
131
- yajl_free_error(hand, str);
132
- break;
133
- }
134
- }
135
-
136
- // parse any remaining buffered data
137
- stat = yajl_parse_complete(hand);
138
- yajl_free(hand);
139
-
140
- return rb_ary_pop(ctx);
141
- }
142
-
143
- VALUE mYajl;
144
- VALUE mNative;
145
-
146
- void Init_yajl() {
147
- mYajl = rb_define_module("Yajl");
148
- mNative = rb_define_module_under(mYajl, "Native");
149
- rb_define_module_function(mNative, "parse", t_parse, 1);
150
- }