Skip to content

Commit f328251

Browse files
committed
Gon is class now
1 parent 0bc017c commit f328251

File tree

10 files changed

+19
-61
lines changed

10 files changed

+19
-61
lines changed

lib/gon.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
require 'gon/jbuilder'
1717
end
1818

19-
module Gon
19+
class Gon
2020
class << self
2121

2222
def global
@@ -70,12 +70,7 @@ def get_variable(name)
7070
end
7171

7272
def set_variable(name, value)
73-
if Gon::Watch.need_return?
74-
Gon::Watch.clear
75-
Gon::Watch.return_variable(value)
76-
else
77-
Request.gon[name] = value
78-
end
73+
Request.gon[name] = value
7974
end
8075

8176
def store_builder_data(builder, data, options)

lib/gon/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Gon
1+
class Gon
22
module Base
33
class << self
44

lib/gon/escaper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Gon
1+
class Gon
22
module Escaper
33
class << self
44

lib/gon/global.rb

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,29 @@
1-
module Gon
2-
module Global
1+
class Gon
2+
class Global < Gon
33
class << self
44

55
def all_variables
66
@global_vars || {}
77
end
88

9-
def method_missing(method, *args, &block)
10-
@global_vars ||= {}
11-
if ( method.to_s =~ /=$/ )
12-
if public_method_name? method
13-
raise "You can't use Gon public methods for storing data"
14-
end
15-
16-
@global_vars[method.to_s.delete('=')] = args[0]
17-
else
18-
@global_vars[method.to_s]
19-
end
20-
end
21-
22-
def rabl(*args)
23-
data, options = Gon::Rabl.handler(args, true)
24-
25-
store_builder_data 'rabl', data, options
26-
end
27-
28-
def jbuilder(*args)
29-
data, options = Gon::Jbuilder.handler(args, true)
30-
31-
store_builder_data 'jbuilder', data, options
32-
end
33-
349
def clear
3510
@global_vars = {}
3611
end
3712

3813
def inspect
39-
'Gon'
14+
'Gon::Global'
4015
end
4116

4217
private
4318

44-
def store_builder_data(builder, data, options)
45-
if options[:as]
46-
@global_vars[options[:as].to_s] = data
47-
elsif data.is_a? Hash
48-
data.each do |key, value|
49-
@global_vars[key] = value
50-
end
51-
else
52-
@global_vars[builder] = data
53-
end
19+
def get_variable(name)
20+
@global_vars ||= {}
21+
@global_vars[name]
5422
end
5523

56-
def public_method_name?(method)
57-
public_methods.include?(
58-
if RUBY_VERSION > '1.9'
59-
method.to_s[0..-2].to_sym
60-
else
61-
method.to_s[0..-2]
62-
end
63-
)
24+
def set_variable(name, value)
25+
@global_vars ||= {}
26+
@global_vars[name] = value
6427
end
6528

6629
end

lib/gon/helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Gon
1+
class Gon
22
module Helpers
33

44
def self.included base

lib/gon/jbuilder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Gon
1+
class Gon
22
module Jbuilder
33
class << self
44

lib/gon/rabl.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'action_view'
22
require 'rabl'
33

4-
module Gon
4+
class Gon
55
module Rabl
66
class << self
77

lib/gon/request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Gon
1+
class Gon
22
module Request
33
class << self
44

lib/gon/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module Gon
1+
class Gon
22
VERSION = '4.0.0beta'
33
end

lib/gon/watch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Gon
1+
class Gon
22
class Watch
33
class << self
44

0 commit comments

Comments
 (0)