Class: Moonrope::DSL::BaseDSL
- Inherits:
-
Object
- Object
- Moonrope::DSL::BaseDSL
- Defined in:
- lib/moonrope/dsl/base_dsl.rb
Instance Method Summary collapse
-
#authenticator { ... } ⇒ Object
Set the authenticator for the API.
-
#controller(name) { ... } ⇒ Object
Define a new controller or append values to an existing controller if it has already been defined.
-
#default_access(value = nil) { ... } ⇒ Object
Set the default access check block.
-
#helper(name, options = {}) { ... } ⇒ Object
Define a new helper in the global namespace.
-
#initialize(base) ⇒ BaseDSL
constructor
Initiaize a new BaseDSL.
-
#structure(name) { ... } ⇒ Object
Define a new structure.
Constructor Details
#initialize(base) ⇒ BaseDSL
Initiaize a new BaseDSL
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.
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.
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.
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
74 75 76 77 78 79 80 81 82 |
# File 'lib/moonrope/dsl/base_dsl.rb', line 74 def helper(name, = {}, &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, , &block) @base.helpers << helper_instance helper_instance end |
#structure(name) { ... } ⇒ Object
Define a new structure
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 |