gon 4.0.2 → 4.0.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of gon might be problematic. Click here for more details.
- data/CHANGELOG.md +7 -0
- data/README.md +8 -0
- data/lib/gon.rb +10 -2
- data/lib/gon/version.rb +1 -1
- data/spec/gon/basic_spec.rb +34 -0
- metadata +3 -3
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 4.0.3
|
4
|
+
|
5
|
+
* Added new method `Gon#push` for assign variables through Hash-like
|
6
|
+
objects (topdev)
|
7
|
+
* Fixes for 1.8.7 compatibility.
|
8
|
+
* !!!IMPORTANT!!! Last version with compatibility for MRI 1.8.7
|
9
|
+
|
3
10
|
## 4.0.2
|
4
11
|
|
5
12
|
* Fixed gon.watch in JS without callback and options
|
data/README.md
CHANGED
@@ -41,6 +41,14 @@ gem line to your Gemfile and do the following:
|
|
41
41
|
|
42
42
|
``` ruby
|
43
43
|
gon.variable_name = variable_value
|
44
|
+
|
45
|
+
# or new syntax
|
46
|
+
gon.push({
|
47
|
+
:user_id => 1,
|
48
|
+
:user_role => "admin"
|
49
|
+
})
|
50
|
+
|
51
|
+
gon.push(any_object) # any_object with respond_to? :each_pair
|
44
52
|
```
|
45
53
|
|
46
54
|
2. In your js you get this by
|
data/lib/gon.rb
CHANGED
@@ -44,6 +44,14 @@ class Gon
|
|
44
44
|
Request.gon[name] = value
|
45
45
|
end
|
46
46
|
|
47
|
+
def push(data = {})
|
48
|
+
raise "Object must have each_pair method" unless data.respond_to? :each_pair
|
49
|
+
|
50
|
+
data.each_pair do |name, value|
|
51
|
+
set_variable(name.to_s, value)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
47
55
|
def all_variables
|
48
56
|
Request.gon
|
49
57
|
end
|
@@ -53,7 +61,7 @@ class Gon
|
|
53
61
|
end
|
54
62
|
|
55
63
|
def rabl(*args)
|
56
|
-
unless Gon.constants.include?(:Rabl)
|
64
|
+
unless Gon.constants.map(&:to_sym).include?(:Rabl)
|
57
65
|
raise "Possible wrong require order problem - try to add `gem 'rabl'` before `gem 'gon'` in your Gemfile"
|
58
66
|
end
|
59
67
|
data, options = Gon::Rabl.handler(args)
|
@@ -62,7 +70,7 @@ class Gon
|
|
62
70
|
end
|
63
71
|
|
64
72
|
def jbuilder(*args)
|
65
|
-
unless Gon.constants.include?(:Jbuilder)
|
73
|
+
unless Gon.constants.map(&:to_sym).include?(:Jbuilder)
|
66
74
|
raise "Possible wrong require order problem - try to add `gem 'jbuilder'` before `gem 'gon'` in your Gemfile"
|
67
75
|
end
|
68
76
|
data, options = Gon::Jbuilder.handler(args)
|
data/lib/gon/version.rb
CHANGED
data/spec/gon/basic_spec.rb
CHANGED
@@ -47,6 +47,20 @@ describe Gon do
|
|
47
47
|
Gon.get_variable(var_name).should == 1
|
48
48
|
end
|
49
49
|
|
50
|
+
it 'can be support new push syntax' do
|
51
|
+
Gon.clear
|
52
|
+
|
53
|
+
Gon.push({ :int => 1, :string => 'string' })
|
54
|
+
Gon.all_variables.should == { :int => 1, :string => 'string' }
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'push with wrong object' do
|
58
|
+
expect {
|
59
|
+
Gon.clear
|
60
|
+
Gon.push(String.new("string object"))
|
61
|
+
}.to raise_error("Object must have each_pair method")
|
62
|
+
end
|
63
|
+
|
50
64
|
end
|
51
65
|
|
52
66
|
describe '#include_gon' do
|
@@ -134,6 +148,26 @@ describe Gon do
|
|
134
148
|
lambda { Gon.rabl = 123 }.should raise_error
|
135
149
|
end
|
136
150
|
|
151
|
+
|
152
|
+
describe '#check_for_rabl_and_jbuilder' do
|
153
|
+
|
154
|
+
let(:controller) { ActionController::Base.new }
|
155
|
+
|
156
|
+
it 'should be able to handle ruby 1.8.7 style constants array (strings)' do
|
157
|
+
constants_as_strings = Gon.constants.map(&:to_s)
|
158
|
+
Gon.stub(:constants) { constants_as_strings }
|
159
|
+
lambda { Gon.rabl 'spec/test_data/sample.rabl', :controller => controller }.should_not raise_error
|
160
|
+
lambda { Gon.jbuilder 'spec/test_data/sample.json.jbuilder', :controller => controller }.should_not raise_error
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'should be able to handle ruby 1.9+ style constants array (symbols)' do
|
164
|
+
constants_as_symbols = Gon.constants.map(&:to_sym)
|
165
|
+
Gon.stub(:constants) { constants_as_symbols }
|
166
|
+
lambda { Gon.rabl 'spec/test_data/sample.rabl', :controller => controller }.should_not raise_error
|
167
|
+
lambda { Gon.jbuilder 'spec/test_data/sample.json.jbuilder', :controller => controller }.should_not raise_error
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
137
171
|
def request
|
138
172
|
@request ||= double 'request', :env => {}
|
139
173
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.3
|
5
5
|
prerelease:
|
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:
|
12
|
+
date: 2013-04-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
171
|
rubyforge_project: gon
|
172
|
-
rubygems_version: 1.8.
|
172
|
+
rubygems_version: 1.8.23
|
173
173
|
signing_key:
|
174
174
|
specification_version: 3
|
175
175
|
summary: Get your Rails variables in your JS
|