Module: ModablesDSL::DSL
- Defined in:
- lib/modables_dsl/dsl/core.rb,
lib/modables_dsl/dsl/arguments.rb
Defined Under Namespace
Classes: Args
Class Method Summary collapse
-
.arguments(&block) ⇒ Object
The arguments block is invoked inside section block to further build the hash.
- .encode_json ⇒ Object
-
.method_missing(meth, *args, &block) ⇒ Object
There are a number of sections supported, account for all of them.
- .morb ⇒ Object
-
.section(*scaffold, &block) ⇒ Object
The section scaffolding is built by reading an array and creating a hash with each element as a nested key of the previous element.
Class Method Details
.arguments(&block) ⇒ Object
The arguments block is invoked inside section block to further build the hash.
19 20 21 22 23 |
# File 'lib/modables_dsl/dsl/core.rb', line 19 def self.arguments &block build = ModablesDSL::DSL::Args.new build.instance_eval(&block) build.args_h end |
.encode_json ⇒ Object
25 26 27 |
# File 'lib/modables_dsl/dsl/core.rb', line 25 def self.encode_json ActiveSupport::JSON.encode(@data) end |
.method_missing(meth, *args, &block) ⇒ Object
There are a number of sections supported, account for all of them.
14 15 16 |
# File 'lib/modables_dsl/dsl/core.rb', line 14 def self.method_missing meth, *args, &block self.section(*args.unshift(meth), &block) end |
.morb ⇒ Object
29 30 31 32 |
# File 'lib/modables_dsl/dsl/core.rb', line 29 def self.morb yield self.encode_json end |
.section(*scaffold, &block) ⇒ Object
The section scaffolding is built by reading an array and creating a hash with each element as a nested key of the previous element.
6 7 8 9 10 11 |
# File 'lib/modables_dsl/dsl/core.rb', line 6 def self.section *scaffold, &block @data = Hash.new if @data.nil? config_block = scaffold.reverse.inject(self.arguments(&block)) { |k, v| { v => k } } @data.deep_merge!(config_block) end |