Class: Lluminary::Schema::ElementTypeSchema
- Inherits:
-
Object
- Object
- Lluminary::Schema::ElementTypeSchema
- Defined in:
- lib/lluminary/schema.rb
Overview
Internal class for defining element types for arrays and dictionaries (or any other container-type objects)
Instance Method Summary collapse
- #array(description: nil, &block) ⇒ Object
- #boolean(description: nil) ⇒ Object
- #datetime(description: nil) ⇒ Object
- #dictionary(description: nil, &block) ⇒ Object
- #float(description: nil) ⇒ Object
- #hash(description: nil, &block) ⇒ Object
- #integer(description: nil) ⇒ Object
- #string(description: nil) ⇒ Object
Instance Method Details
#array(description: nil, &block) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/lluminary/schema.rb', line 130 def array(description: nil, &block) field = { type: :array, description: description } field[:element_type] = ElementTypeSchema.new.instance_eval( &block ) if block field end |
#boolean(description: nil) ⇒ Object
118 119 120 |
# File 'lib/lluminary/schema.rb', line 118 def boolean(description: nil) { type: :boolean, description: description } end |
#datetime(description: nil) ⇒ Object
126 127 128 |
# File 'lib/lluminary/schema.rb', line 126 def datetime(description: nil) { type: :datetime, description: description } end |
#dictionary(description: nil, &block) ⇒ Object
149 150 151 152 153 154 155 156 157 158 |
# File 'lib/lluminary/schema.rb', line 149 def dictionary(description: nil, &block) unless block raise ArgumentError, "Dictionary fields must be defined with a block" end element_schema = ElementTypeSchema.new value_type = element_schema.instance_eval(&block) { type: :dictionary, description: description, value_type: value_type } end |
#float(description: nil) ⇒ Object
122 123 124 |
# File 'lib/lluminary/schema.rb', line 122 def float(description: nil) { type: :float, description: description } end |
#hash(description: nil, &block) ⇒ Object
138 139 140 141 142 143 144 145 146 147 |
# File 'lib/lluminary/schema.rb', line 138 def hash(description: nil, &block) unless block raise ArgumentError, "Hash fields must be defined with a block" end nested_schema = Schema.new nested_schema.instance_eval(&block) { type: :hash, description: description, fields: nested_schema.fields } end |
#integer(description: nil) ⇒ Object
114 115 116 |
# File 'lib/lluminary/schema.rb', line 114 def integer(description: nil) { type: :integer, description: description } end |
#string(description: nil) ⇒ Object
110 111 112 |
# File 'lib/lluminary/schema.rb', line 110 def string(description: nil) { type: :string, description: description } end |