Class: Comatose::ProcessingContext

Inherits:
Hash
  • Object
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

#initialize(page, params = {}) ⇒ ProcessingContext

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
  #Comatose.logger.debug("params in ProcessingContext: #{params}")
  @system       = params.delete('system')  || {}
  @current_user = @system['current_user']
  @locals = params
  @page = Comatose::PageWrapper.new(page, @locals, @system)
  #rescue => e
  #  Comatose.logger.debug "ProcessingContext: initialize: #{e.message}"
  #  Comatose.logger.debug e.backtrace.join("\n")
  #  raise e
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)
  #Comatose.logger.debug("processing_context: method_missing: method: #{method_id}")
  #Comatose.logger.debug("processing_context: method_missing: args: #{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)
    #else Hash.respond_to?(method_id)
    #  super(method_id, args)
    #else
    #  "ProcessingContext: Couldn't find #{method_id}"
  end
end

Instance Attribute Details

#current_userObject

Returns the value of attribute current_user.



6
7
8
# File 'lib/comatose/processing_context.rb', line 6

def current_user
  @current_user
end

#localsObject

Returns the value of attribute locals.



6
7
8
# File 'lib/comatose/processing_context.rb', line 6

def locals
  @locals
end

#pageObject

Returns the value of attribute page.



6
7
8
# File 'lib/comatose/processing_context.rb', line 6

def page
  @page
end

#systemObject

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)
  #Comatose.logger.debug "[] called with key: #{key}"
  #Comatose.logger.debug "current_user: #{current_user.to_s}"
  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 = Page.find_by_path(path)
    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_bindingObject



70
71
72
# File 'lib/comatose/processing_context.rb', line 70

def get_binding
  binding
end

#has_key?(key) ⇒ Boolean

Returns:

  • (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

#inspectObject



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_liquidObject



65
66
67
# File 'lib/comatose/processing_context.rb', line 65

def to_liquid
  self
end