Class: Action

Inherits:
Object
  • Object
show all
Defined in:
lib/culpa/action.rb

Defined Under Namespace

Classes: RenderNow

Constant Summary collapse

@@renderers =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(envelope, request, session) ⇒ Action

Returns a new instance of Action.



29
30
31
32
33
# File 'lib/culpa/action.rb', line 29

def initialize(envelope, request, session)
  @e = envelope
  @r = request
  @session = session
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym) ⇒ Object



35
36
37
# File 'lib/culpa/action.rb', line 35

def method_missing(sym)
  @r.send(sym)
end

Instance Attribute Details

#eObject (readonly)

Returns the value of attribute e.



20
21
22
# File 'lib/culpa/action.rb', line 20

def e
  @e
end

#rObject (readonly)

Returns the value of attribute r.



20
21
22
# File 'lib/culpa/action.rb', line 20

def r
  @r
end

#sessionObject (readonly)

Returns the value of attribute session.



20
21
22
# File 'lib/culpa/action.rb', line 20

def session
  @session
end

Class Method Details

.add_renderer(filepath) ⇒ Object



10
11
12
# File 'lib/culpa/action.rb', line 10

def self.add_renderer(filepath)
  @@renderers.merge!(RendererDescriber.new(filepath).result)
end

.load_renderersObject



14
15
16
17
18
# File 'lib/culpa/action.rb', line 14

def self.load_renderers
  Dir[File.join(File.dirname(__FILE__), 'renderers/*.rb')].each do |renderer|
    @@renderers.merge!(RendererDescriber.new(renderer).result)
  end
end

.renderers_listObject



6
7
8
# File 'lib/culpa/action.rb', line 6

def self.renderers_list
  @@renderers
end

Instance Method Details

#render(options = {}) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/culpa/action.rb', line 39

def render(options = {})
  keyword = options.keys.first
  options[:headers] ||= {}
  raise Culpa::UnknownRenderCall unless @@renderers.include?(keyword)
  to_render = @@renderers[keyword].call(options, @e)
  raise RenderNow, to_render
end