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



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

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

Instance Attribute Details

#access_ruleObject

Returns the value of attribute access_rule.



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

def access_rule
  @access_rule
end

#actionsObject

Returns the value of attribute actions.



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

def actions
  @actions
end

#authenticatorObject

Returns the value of attribute authenticator.



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

def authenticator
  @authenticator
end

#baseObject (readonly)

Returns the value of attribute base.



7
8
9
# File 'lib/moonrope/controller.rb', line 7

def base
  @base
end

#beforesObject

Returns the value of attribute befores.



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

def befores
  @befores
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#docObject

Returns the value of attribute doc.



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

def doc
  @doc
end

#dslObject (readonly)

Returns the value of attribute dsl.



7
8
9
# File 'lib/moonrope/controller.rb', line 7

def dsl
  @dsl
end

#friendly_nameObject

Returns the value of attribute friendly_name.



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

def friendly_name
  @friendly_name
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#shared_actionsObject

Returns the value of attribute shared_actions.



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

def shared_actions
  @shared_actions
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:



45
46
47
# File 'lib/moonrope/controller.rb', line 45

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



33
34
35
36
37
# File 'lib/moonrope/controller.rb', line 33

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