json_builder 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json_builder (3.0.1)
4
+ json_builder (3.0.2)
5
5
  activesupport (>= 2.0.0)
6
6
 
7
7
  GEM
@@ -1,4 +1,4 @@
1
- require 'blankslate' unless defined? BlankSlate
1
+ require 'blankslate' unless defined?(BlankSlate)
2
2
  require 'json_builder/member'
3
3
 
4
4
  module JSONBuilder
@@ -24,7 +24,8 @@ module JSONBuilder
24
24
  @_callback = options[:callback] || true
25
25
  @_pretty_print = options[:pretty] || false
26
26
 
27
- copy_instance_variables_from(@_scope, [:@assigns, :@helpers])
27
+ # Only copy instance variables if there is a scope and presence of Rails
28
+ copy_instance_variables_from(@_scope) if @_scope
28
29
  end
29
30
 
30
31
  def compile(*args, &block)
@@ -32,14 +33,18 @@ module JSONBuilder
32
33
  end
33
34
 
34
35
  def array(items, &block)
35
- @_array = Elements.new(items, &block)
36
+ @_array = Elements.new(@_scope, items, &block)
36
37
  end
37
38
 
38
39
  # Need to return a Key instance to allow for arrays to be handled appropriately
39
40
  def method_missing(key, *args, &block)
40
- member = Member.new(key, *args, &block)
41
- @_members << member
42
- member
41
+ if @_scope.respond_to?(key)
42
+ @_scope.send(key, *args, &block)
43
+ else
44
+ member = Member.new(key, @_scope, *args, &block)
45
+ @_members << member
46
+ member
47
+ end
43
48
  end
44
49
  alias_method :key, :method_missing
45
50
 
@@ -2,11 +2,11 @@ module JSONBuilder
2
2
  class Elements
3
3
  attr_accessor :compilers
4
4
 
5
- def initialize(items, &block)
5
+ def initialize(scope, items, &block)
6
6
  @compilers = []
7
7
 
8
8
  items.each do |item|
9
- @compilers << Value.new(item, &block)
9
+ @compilers << Value.new(scope, item, &block)
10
10
  end
11
11
  end
12
12
 
@@ -6,14 +6,14 @@ module JSONBuilder
6
6
  attr_accessor :key
7
7
  attr_accessor :value
8
8
 
9
- def initialize(key, *args, &block)
9
+ def initialize(key, scope, *args, &block)
10
10
  @key = key
11
-
11
+
12
12
  argument = args.shift
13
13
  if argument.is_a?(Array)
14
- @value = Elements.new(argument, &block)
14
+ @value = Elements.new(scope, argument, &block)
15
15
  else
16
- @value = Value.new(argument, &block)
16
+ @value = Value.new(scope, argument, &block)
17
17
  end
18
18
  end
19
19
 
@@ -4,10 +4,10 @@ module JSONBuilder
4
4
  class Value
5
5
  attr_accessor :value
6
6
 
7
- def initialize(arg, &block)
7
+ def initialize(scope, arg, &block)
8
8
  if block_given?
9
- @value = Compiler.new
10
- compiled = @value.compile(*arg, &block)
9
+ @value = Compiler.new(:scope => scope)
10
+ compiled = @value.compile(arg, &block)
11
11
 
12
12
  # For the use case that the passed in block returns a non-member object
13
13
  # or normal Ruby object
@@ -1,3 +1,3 @@
1
1
  module JSONBuilder
2
- VERSION = '3.0.1'
2
+ VERSION = '3.0.2'
3
3
  end
@@ -1,2 +1,5 @@
1
1
  module UsersHelper
2
+ def included_helper
3
+ "yes"
4
+ end
2
5
  end
@@ -1,4 +1,15 @@
1
+ id 1
1
2
  testing ["1", 2, true] do |t|
3
+ id t
2
4
  variable t
5
+ url users_path
6
+ help included_helper
7
+ name @user.name
8
+ code { root_path }
9
+ deep do
10
+ node included_helper
11
+ url root_path
12
+ end
3
13
  end
4
- name @user.name
14
+ url users_path
15
+ name @user.name
@@ -1,5 +1,5 @@
1
1
  Dummy::Application.routes.draw do
2
2
  resources :users, :only => [:index]
3
3
 
4
- # root :to => "welcome#index"
4
+ root :to => 'users#index'
5
5
  end
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.1
4
+ version: 3.0.2
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-28 00:00:00.000000000Z
12
+ date: 2011-11-29 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70225675808800 !ruby/object:Gem::Requirement
16
+ requirement: &70301327866900 !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: *70225675808800
24
+ version_requirements: *70301327866900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70225675808340 !ruby/object:Gem::Requirement
27
+ requirement: &70301327866480 !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: *70225675808340
35
+ version_requirements: *70301327866480
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: 1941851873589060852
122
+ hash: -1953175025481135618
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: 1941851873589060852
131
+ hash: -1953175025481135618
132
132
  requirements: []
133
133
  rubyforge_project:
134
134
  rubygems_version: 1.8.10