Class: Moonrope::DSL::ActionDSL

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

Instance Method Summary collapse

Constructor Details

#initialize(action) ⇒ ActionDSL

Initialize a new ActionDSL

Parameters:



10
11
12
# File 'lib/moonrope/dsl/action_dsl.rb', line 10

def initialize(action)
  @action = action
end

Instance Method Details

#access(value = nil) { ... } ⇒ void

This method returns an undefined value.

Set the access condition for the action.

access do
  auth.is_a?(User)
end

Yields:

  • the contents of the yield will be saved as the access condition



50
51
52
# File 'lib/moonrope/dsl/action_dsl.rb', line 50

def access(value = nil, &block)
  @action.access = block_given? ? block : value
end

#action { ... } ⇒ void

This method returns an undefined value.

Set the action to execute when this action is invoked.

action do
  # Do something here and return a JSON-able value
end

Yields:

  • the contents of the yield will be saved as the action



64
65
66
# File 'lib/moonrope/dsl/action_dsl.rb', line 64

def action(&block)
  @action.action = block
end

#description(value) ⇒ void

This method returns an undefined value.

Set the description for the action

description "Returns all users which are configured"

Parameters:

  • value (String)


22
23
24
# File 'lib/moonrope/dsl/action_dsl.rb', line 22

def description(value)
  @action.description = value
end

#param(name, description, options = {}) ⇒ void

This method returns an undefined value.

Add a new param to the action’s param set.

param :page, "The page number", :default => 2

Parameters:

  • name (Symbol)

    the name of the param

  • description (String)

    a description of the action

  • options (Hash) (defaults to: {})

    a hash of additional options



36
37
38
# File 'lib/moonrope/dsl/action_dsl.rb', line 36

def param(name, description, options = {})
  @action.params[name] = options.merge(:description => description)
end