Class: Gon::Sinatra::Store
- Inherits:
-
Object
- Object
- Gon::Sinatra::Store
show all
- Defined in:
- lib/gon/sinatra/store.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(variables) ⇒ Store
Returns a new instance of Store.
6
7
8
|
# File 'lib/gon/sinatra/store.rb', line 6
def initialize(variables)
@env = variables
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/gon/sinatra/store.rb', line 18
def method_missing(method, *args, &block)
if ( method.to_s =~ /=$/ )
if public_methods.include? method.to_s[0..-2].to_sym
raise "You can't use Gon public methods for storing data"
end
set_variable(method.to_s.delete('='), args[0])
else
get_variable(method.to_s)
end
end
|
Instance Attribute Details
#request ⇒ Object
Returns the value of attribute request.
4
5
6
|
# File 'lib/gon/sinatra/store.rb', line 4
def request
@request
end
|
Instance Method Details
#all_variables ⇒ Object
10
11
12
|
# File 'lib/gon/sinatra/store.rb', line 10
def all_variables
@env
end
|
#clear ⇒ Object
14
15
16
|
# File 'lib/gon/sinatra/store.rb', line 14
def clear
@env.clear
end
|
#get_variable(name) ⇒ Object
Also known as:
get
29
30
31
|
# File 'lib/gon/sinatra/store.rb', line 29
def get_variable(name)
@env && @env[name]
end
|
#jbuilder(view_path, options = {}) ⇒ Object
61
62
63
|
# File 'lib/gon/sinatra/store.rb', line 61
def jbuilder(view_path, options = {})
raise NoMethodError.new("Not available for sinatra")
end
|
#rabl(view_path, options = {}) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/gon/sinatra/store.rb', line 39
def rabl(view_path, options = {})
unless defined?(::Rabl)
raise Exception.new("You must require rabl and register Gon::Sinatra::Rabl to use rabl")
end
unless options[:instance]
raise ArgumentError.new("You should pass :instance in options: :instance => self")
end
rabl_data = Gon::Sinatra::Rabl.parse_rabl(view_path, options[:instance])
if options[:as]
set_variable(options[:as].to_s, rabl_data)
elsif rabl_data.is_a? Hash
rabl_data.each do |key, value|
set_variable(key, value)
end
else
set_variable('rabl', rabl_data)
end
end
|
#set_variable(name, value) ⇒ Object
Also known as:
set
34
35
36
|
# File 'lib/gon/sinatra/store.rb', line 34
def set_variable(name, value)
@env[name] = value
end
|