Class: Moonrope::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/moonrope/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, name) { ... } ⇒ Controller

Initalize a new Moonrope::Controller

Parameters:

  • base (Moonrope::Base)

    the base

  • name (Symbol)

    the name of the controller

Yields:

  • instance evals the contents within the ControllerDSL



14
15
16
17
18
19
20
21
22
# File 'lib/moonrope/controller.rb', line 14

def initialize(base, name, &block)
  @base = base
  @name = name
  @actions = {}
  @access = nil
  @befores = []
  @dsl = Moonrope::DSL::ControllerDSL.new(self)
  @dsl.instance_eval(&block) if block_given?
end

Instance Attribute Details

#accessObject

Returns the value of attribute access.



4
5
6
# File 'lib/moonrope/controller.rb', line 4

def access
  @access
end

#actionsObject

Returns the value of attribute actions.



4
5
6
# File 'lib/moonrope/controller.rb', line 4

def actions
  @actions
end

#baseObject (readonly)

Returns the value of attribute base.



5
6
7
# File 'lib/moonrope/controller.rb', line 5

def base
  @base
end

#beforesObject

Returns the value of attribute befores.



4
5
6
# File 'lib/moonrope/controller.rb', line 4

def befores
  @befores
end

#dslObject (readonly)

Returns the value of attribute dsl.



5
6
7
# File 'lib/moonrope/controller.rb', line 5

def dsl
  @dsl
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/moonrope/controller.rb', line 4

def name
  @name
end

Instance Method Details

#action(action) ⇒ Moonrope::Action Also known as: /

Lookup and return an action in this controller by name.

Parameters:

  • action (Symbol)

    the name of the action

Returns:



43
44
45
# File 'lib/moonrope/controller.rb', line 43

def action(action)
  actions[action.to_sym]
end

#before_actions_for(action) ⇒ Array

Return an array of before actions which must be executed for the given action.

Parameters:

  • action (Symbol)

    the name of the action to return

Returns:

  • (Array)

    an array of Moonrope::BeforeAction instances



31
32
33
34
35
# File 'lib/moonrope/controller.rb', line 31

def before_actions_for(action)
  @befores.select do |b|
    b.actions.empty? || b.actions.include?(action)
  end
end