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:



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

def initialize(base)
  @base = base
end

Instance Method Details

#authenticator { ... } ⇒ Object

Set the authenticator for the API.

Yields:

  • stores the block as the authenticator



55
56
57
# File 'lib/moonrope/dsl/base_dsl.rb', line 55

def authenticator(&block)
  @base.authenticator = block
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



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/moonrope/dsl/base_dsl.rb', line 38

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

#default_access(value = nil) { ... } ⇒ Object

Set the default access check block.

Yields:

  • stores the block as the access check



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

def default_access(value = nil, &block)
  @base.default_access = block_given? ? block : value
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



74
75
76
77
78
79
80
81
82
# File 'lib/moonrope/dsl/base_dsl.rb', line 74

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

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

Define a new structure

Parameters:

  • name (Symbol)

    the name of the structure

Yields:

  • instance evals the block within the StructureDSL



20
21
22
23
24
25
26
27
28
29
# File 'lib/moonrope/dsl/base_dsl.rb', line 20

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