Class: Moonrope::DSL::StructureDSL
- Inherits:
-
Object
- Object
- Moonrope::DSL::StructureDSL
- Defined in:
- lib/moonrope/dsl/structure_dsl.rb
Instance Attribute Summary collapse
-
#conditions ⇒ Array
Conditions which should applied.
-
#groups ⇒ Array
Groups which should applied.
-
#options ⇒ Hash
Options.
-
#structure ⇒ Moonrope::Structure
readonly
The associated structure.
Instance Method Summary collapse
- #attribute(type, name, description, options = {}) ⇒ Object
- #basic(*args, &block) ⇒ Object
- #condition(condition, &block) ⇒ Object
- #expansion(name, *args, &block) ⇒ Object
- #full(*args, &block) ⇒ Object
- #group(name, &block) ⇒ Object
-
#initialize(structure) ⇒ StructureDSL
constructor
Initialize a new StructureDSL.
- #scope(options = {}, &block) ⇒ Object
Constructor Details
#initialize(structure) ⇒ StructureDSL
Initialize a new StructureDSL
22 23 24 25 26 27 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 22 def initialize(structure) @structure = structure @options = {} @groups = [] @conditions = [] end |
Instance Attribute Details
#conditions ⇒ Array
Returns conditions which should applied.
12 13 14 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 12 def conditions @conditions end |
#groups ⇒ Array
Returns groups which should applied.
9 10 11 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 9 def groups @groups end |
#options ⇒ Hash
Returns options.
15 16 17 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 15 def @options end |
#structure ⇒ Moonrope::Structure (readonly)
Returns the associated structure.
6 7 8 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 6 def structure @structure end |
Instance Method Details
#attribute(type, name, description, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 47 def attribute(type, name, description, = {}) attribute = StructureAttribute.new(type, name, description) attribute.structure = [:structure] attribute.structure_opts = [:structure_opts] attribute.value_type = [:type] attribute.source_attribute = [:source_attribute] attribute.value = [:value] attribute.example = [:eg] || [:example] attribute.groups = @groups attribute.conditions = @conditions @structure.attributes[type] << attribute end |
#basic(*args, &block) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 60 def basic(*args, &block) if block_given? @structure.basic = block else attribute(:basic, *args) end end |
#condition(condition, &block) ⇒ Object
41 42 43 44 45 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 41 def condition(condition, &block) scope_dsl = self.class.new(@structure) scope_dsl.conditions = [@conditions, condition].flatten scope_dsl.instance_eval(&block) end |
#expansion(name, *args, &block) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 76 def expansion(name, *args, &block) if block_given? @structure.expansions[name] = block else attribute(:expansion, name, *args) end end |
#full(*args, &block) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 68 def full(*args, &block) if block_given? @structure.full = block else attribute(:full, *args) end end |
#group(name, &block) ⇒ Object
35 36 37 38 39 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 35 def group(name, &block) scope_dsl = self.class.new(@structure) scope_dsl.groups = [@groups, name].flatten scope_dsl.instance_eval(&block) end |
#scope(options = {}, &block) ⇒ Object
29 30 31 32 33 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 29 def scope( = {}, &block) scope_dsl = self.class.new(@structure) scope_dsl. = scope_dsl.instance_eval(&block) end |