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, options_or_description = {}, options_if_description = {}) ⇒ Object
- #basic(*args, &block) ⇒ Object
- #condition(condition, description = nil, &block) ⇒ Object
- #expansion(name, *args, &block) ⇒ Object
- #full(*args, &block) ⇒ Object
- #group(name, &block) ⇒ Object
-
#initialize(structure) ⇒ StructureDSL
constructor
Initialize a new StructureDSL.
- #no_doc! ⇒ Object
- #scope(options = {}, &block) ⇒ Object
Constructor Details
#initialize(structure) ⇒ StructureDSL
Initialize a new StructureDSL
24 25 26 27 28 29 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 24 def initialize(structure) @structure = structure @options = {} @groups = [] @conditions = [] end |
Instance Attribute Details
#conditions ⇒ Array
Returns conditions which should applied.
14 15 16 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 14 def conditions @conditions end |
#groups ⇒ Array
Returns groups which should applied.
11 12 13 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 11 def groups @groups end |
#options ⇒ Hash
Returns options.
17 18 19 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 17 def @options end |
#structure ⇒ Moonrope::Structure (readonly)
Returns the associated structure.
8 9 10 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 8 def structure @structure end |
Instance Method Details
#attribute(type, name, options_or_description = {}, options_if_description = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 62 def attribute(type, name, = {}, = {}) if .is_a?(String) [:description] = = else = end attribute = StructureAttribute.new(type, name) attribute.description = [: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.doc = [:doc] attribute.mutation = [:mutation] attribute.groups = @groups attribute.conditions = @conditions @structure.attributes[type] << attribute end |
#basic(*args, &block) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 86 def basic(*args, &block) if block_given? @structure.basic = block else attribute(:basic, *args) end end |
#condition(condition, description = nil, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 48 def condition(condition, description = nil, &block) scope_dsl = self.class.new(@structure) if condition.is_a?(Hash) && condition.size == 1 condition = {:authenticator => condition.first[0], :access_rule => condition.first[1]} elsif condition.is_a?(Symbol) condition = {:authenticator => :default, :access_rule => condition} else condition = {:block => condition, :description => description} end scope_dsl.conditions = [@conditions, condition].flatten scope_dsl.groups = @groups scope_dsl.instance_eval(&block) end |
#expansion(name, *args, &block) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 102 def expansion(name, *args, &block) if block_given? if args[0].is_a?(String) attrs = args[1] || {} attrs[:description] = args[0] elsif args[0].is_a?(Hash) attrs = atrs[0] else attrs = {} end @structure.expansions[name] = attrs.merge({:block => block, :conditions => @conditions}) else attribute(:expansion, name, *args) end end |
#full(*args, &block) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 94 def full(*args, &block) if block_given? @structure.full = block else attribute(:full, *args) end end |
#group(name, &block) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 41 def group(name, &block) scope_dsl = self.class.new(@structure) scope_dsl.groups = [@groups, name].flatten scope_dsl.conditions = @conditions scope_dsl.instance_eval(&block) end |
#no_doc! ⇒ Object
31 32 33 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 31 def no_doc! @structure.doc = false end |
#scope(options = {}, &block) ⇒ Object
35 36 37 38 39 |
# File 'lib/moonrope/dsl/structure_dsl.rb', line 35 def scope( = {}, &block) scope_dsl = self.class.new(@structure) scope_dsl. = scope_dsl.instance_eval(&block) end |