Class: Comatose::ProcessingContext
- Inherits:
-
Hash
- Object
- Hash
- Comatose::ProcessingContext
show all
- Defined in:
- lib/comatose/processing_context.rb
Constant Summary
collapse
- @@supported_methods =
%w( page include current_user )
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ProcessingContext.
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/comatose/processing_context.rb', line 9
def initialize(page, params={})
params = params.stringify_keys rescue params
@system = params.delete('system') || {}
@current_user = @system['current_user']
@locals = params
@page = Comatose::PageWrapper.new(page, @locals, @system)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *args) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/comatose/processing_context.rb', line 80
def method_missing(method_id, *args)
method_name = method_id.to_s
case
when locals.has_key?(method_name)
locals[method_name]
when page.respond_to?(method_name)
page.send(method_name, args)
when Comatose.registered_drops.has_key?(method_name)
Comatose.registered_drops[method_name].context = self
Comatose.registered_drops[method_name].send(args)
end
end
|
Instance Attribute Details
#current_user ⇒ Object
Returns the value of attribute current_user.
6
7
8
|
# File 'lib/comatose/processing_context.rb', line 6
def current_user
@current_user
end
|
#locals ⇒ Object
Returns the value of attribute locals.
6
7
8
|
# File 'lib/comatose/processing_context.rb', line 6
def locals
@locals
end
|
#page ⇒ Object
Returns the value of attribute page.
6
7
8
|
# File 'lib/comatose/processing_context.rb', line 6
def page
@page
end
|
#system ⇒ Object
Returns the value of attribute system.
6
7
8
|
# File 'lib/comatose/processing_context.rb', line 6
def system
@system
end
|
Instance Method Details
#[](key) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/comatose/processing_context.rb', line 44
def [](key)
case
when key.to_s.downcase == 'page'
@page
when key.to_s.downcase == 'current_user'
@current_user
when locals.has_key?(key)
locals[key]
when Comatose.registered_drops.has_key?(key)
Comatose.registered_drops[key]
end
end
|
#find_by_path(path) ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/comatose/processing_context.rb', line 33
def find_by_path(path)
begin
Page.send(Comatose.config.page_finder, path)
Comatose::PageWrapper.new(page, self[:locals])
rescue
"<p>Page at <tt>#{path}</tt> could not be found.</p>"
end
end
|
#get_binding ⇒ Object
70
71
72
|
# File 'lib/comatose/processing_context.rb', line 70
def get_binding
binding
end
|
#has_key?(key) ⇒ Boolean
60
61
62
|
# File 'lib/comatose/processing_context.rb', line 60
def has_key?(key)
@@supported_methods.include?(key) or locals.has_key?(key) or Comatose.registered_drops.has_key?(key)
end
|
#inspect ⇒ Object
75
76
77
|
# File 'lib/comatose/processing_context.rb', line 75
def inspect
h = self.dup.merge(:page => page, :current_user => current_user, :locals => locals)
end
|
#to_liquid ⇒ Object
65
66
67
|
# File 'lib/comatose/processing_context.rb', line 65
def to_liquid
self
end
|