json_builder 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json_builder (3.0.0)
4
+ json_builder (3.0.1)
5
5
  activesupport (>= 2.0.0)
6
6
 
7
7
  GEM
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Garrett Bjerkhoel
1
+ Copyright (c) 2011 Garrett Bjerkhoel
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -226,10 +226,6 @@ end
226
226
  ActionView::Base.pretty_print_json = false
227
227
  ```
228
228
 
229
- ## Conversions
230
-
231
- Time - [ISO-8601](http://en.wikipedia.org/wiki/ISO_8601)
232
-
233
229
  ## Speed
234
230
  JSON Builder is very fast, it's roughly 3.6 times faster than the core XML Builder based on the [speed benchmark](http://github.com/dewski/json_builder/blob/master/spec/benchmarks/builder.rb).
235
231
 
@@ -237,9 +233,6 @@ JSON Builder is very fast, it's roughly 3.6 times faster than the core XML Build
237
233
  JSONBuilder 2.950000 0.010000 2.960000 (2.968790)
238
234
  Builder 10.820000 0.040000 10.860000 (10.930497)
239
235
 
240
- ## Examples
241
- See the [examples](http://github.com/dewski/json_builder/tree/master/examples) directory.
242
-
243
236
  ## Note on Patches/Pull Requests
244
237
 
245
238
  - Fork the project.
@@ -19,10 +19,12 @@ module JSONBuilder
19
19
  attr_accessor :pretty_print
20
20
 
21
21
  def initialize(options={})
22
- @members = []
23
- @scope = options[:scope]
24
- @callback = options[:callback]
25
- @pretty_print = options[:pretty]
22
+ @_members = []
23
+ @_scope = options[:scope]
24
+ @_callback = options[:callback] || true
25
+ @_pretty_print = options[:pretty] || false
26
+
27
+ copy_instance_variables_from(@_scope, [:@assigns, :@helpers])
26
28
  end
27
29
 
28
30
  def compile(*args, &block)
@@ -30,34 +32,39 @@ module JSONBuilder
30
32
  end
31
33
 
32
34
  def array(items, &block)
33
- @array = Elements.new(items, &block)
35
+ @_array = Elements.new(items, &block)
34
36
  end
35
37
 
36
38
  # Need to return a Key instance to allow for arrays to be handled appropriately
37
39
  def method_missing(key, *args, &block)
38
40
  member = Member.new(key, *args, &block)
39
- @members << member
41
+ @_members << member
40
42
  member
41
43
  end
42
44
  alias_method :key, :method_missing
43
45
 
44
46
  # Once all nodes are compiled, build the string
45
47
  def to_s
46
- include_callback @array ? @array.to_s : "{#{@members.collect(&:to_s).join(', ')}}"
48
+ include_callback @_array ? @_array.to_s : "{#{@_members.collect(&:to_s).join(', ')}}"
47
49
  end
48
50
 
49
51
  private
50
52
 
51
53
  def include_callback(json)
52
- @callback && request_params[:callback] ? "#{request_params[:callback]}(#{pretty_print(json)})" : pretty_print(json)
54
+ @_callback && request_params[:callback] ? "#{request_params[:callback]}(#{pretty_print(json)})" : pretty_print(json)
53
55
  end
54
56
 
55
57
  def pretty_print(json)
56
- @pretty_print ? JSON.pretty_generate(JSON[json]) : json
58
+ @_pretty_print ? JSON.pretty_generate(JSON[json]) : json
57
59
  end
58
60
 
59
61
  def request_params
60
- @scope.respond_to?(:params) ? @scope.params : {}
62
+ @_scope.respond_to?(:params) ? @_scope.params : {}
63
+ end
64
+
65
+ def copy_instance_variables_from(object, exclude = []) #:nodoc:
66
+ vars = object.instance_variables.map(&:to_s) - exclude.map(&:to_s)
67
+ vars.each { |name| instance_variable_set(name, object.instance_variable_get(name)) }
61
68
  end
62
69
  end
63
70
  end
@@ -5,7 +5,7 @@ module JSONBuilder
5
5
  def initialize(items, &block)
6
6
  @compilers = []
7
7
 
8
- items.compact.each do |item|
8
+ items.each do |item|
9
9
  @compilers << Value.new(item, &block)
10
10
  end
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module JSONBuilder
2
- VERSION = '3.0.0'
2
+ VERSION = '3.0.1'
3
3
  end
@@ -1,8 +1,7 @@
1
- $:.push File.expand_path('../../../lib', __FILE__)
2
1
  require 'rubygems'
3
2
  require 'benchmark'
4
3
  require 'builder'
5
- require 'json_builder/compiler'
4
+ require 'json_builder'
6
5
 
7
6
  Benchmark.bm do |b|
8
7
  b.report('JSONBuilder') do
@@ -1,5 +1,6 @@
1
1
  class UsersController < ApplicationController
2
2
  def index
3
- @users = User.all
3
+ require 'ostruct'
4
+ @user = OpenStruct.new(:name => 'Garrett Bjerkhoel')
4
5
  end
5
6
  end
@@ -1,3 +1,4 @@
1
1
  testing ["1", 2, true] do |t|
2
2
  variable t
3
- end
3
+ end
4
+ name @user.name
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-27 00:00:00.000000000Z
12
+ date: 2011-11-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70289633146840 !ruby/object:Gem::Requirement
16
+ requirement: &70225675808800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70289633146840
24
+ version_requirements: *70225675808800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70289633146020 !ruby/object:Gem::Requirement
27
+ requirement: &70225675808340 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70289633146020
35
+ version_requirements: *70225675808340
36
36
  description: Rails provides an excellent XML Builder by default to build RSS and ATOM
37
37
  feeds, but nothing to help you build complex and custom JSON data structures. The
38
38
  standard to_json works well, but can get very verbose when you need full control
@@ -119,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  segments:
121
121
  - 0
122
- hash: -3090005321848718837
122
+ hash: 1941851873589060852
123
123
  required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  none: false
125
125
  requirements:
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  segments:
130
130
  - 0
131
- hash: -3090005321848718837
131
+ hash: 1941851873589060852
132
132
  requirements: []
133
133
  rubyforge_project:
134
134
  rubygems_version: 1.8.10