Class: Moonrope::DSL::BaseDSL

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

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ BaseDSL

Initiaize a new BaseDSL

Parameters:



14
15
16
# File 'lib/moonrope/dsl/base_dsl.rb', line 14

def initialize(base)
  @base = base
end

Instance Method Details

#authenticator(name, &block) ⇒ Object

Define a new authenticator



73
74
75
76
77
78
# File 'lib/moonrope/dsl/base_dsl.rb', line 73

def authenticator(name, &block)
  authenticator = Moonrope::Authenticator.new(name)
  dsl = Moonrope::DSL::AuthenticatorDSL.new(authenticator)
  dsl.instance_eval(&block) if block_given?
  @base.authenticators[name] = authenticator
end

#controller(name) { ... } ⇒ Object

Define a new controller or append values to an existing controller if it has already been defined.

Parameters:

  • name (Symbol)

    the name of the controller

Yields:

  • instance evals the block within the ControllerDSL



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/moonrope/dsl/base_dsl.rb', line 42

def controller(name, &block)
  existing = @base.controllers.select { |a| a.name == name }.first
  if existing
    controller = existing
  else
    controller = Moonrope::Controller.new(@base, name)
    @base.controllers << controller
  end
  controller.dsl.instance_eval(&block) if block_given?
  controller
end

#helper(name, options = {}) { ... } ⇒ Object

Define a new helper in the global namespace

Parameters:

  • name (Symbol)

    the name of the helper

Yields:

  • stores the block to execute for the helper



60
61
62
63
64
65
66
67
68
# File 'lib/moonrope/dsl/base_dsl.rb', line 60

def helper(name, options = {}, &block)
  if @base.helper(name, nil)
    raise Moonrope::Errors::HelperAlreadyDefined, "Helper has already been defined with name `#{name}`"
  end

  helper_instance = Moonrope::Helper.new(name, nil, options, &block)
  @base.helpers << helper_instance
  helper_instance
end

#shared_action(name, &block) ⇒ Object

Define a new global shared action



83
84
85
# File 'lib/moonrope/dsl/base_dsl.rb', line 83

def shared_action(name, &block)
  @base.shared_actions[name] = block
end

#structure(name) { ... } ⇒ Object

Define a new structure

Parameters:

  • name (Symbol)

    the name of the structure

Yields:

  • instance evals the block within the StructureDSL



24
25
26
27
28
29
30
31
32
33
# File 'lib/moonrope/dsl/base_dsl.rb', line 24

def structure(name, &block)
  if existing = @base.structures.select { |s| s.name == name }.first
    structure = existing
  else
    structure = Moonrope::Structure.new(@base, name)
    @base.structures << structure
  end
  structure.dsl.instance_eval(&block) if block_given?
  structure
end