Class: Mushikago::Hanamgri::Schema
- Inherits:
-
Object
- Object
- Mushikago::Hanamgri::Schema
- Defined in:
- lib/mushikago/hanamgri/schema.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
- #add(field_or_hash) ⇒ Object
-
#initialize(&block) ⇒ Schema
constructor
A new instance of Schema.
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Schema
Returns a new instance of Schema.
8 9 10 11 |
# File 'lib/mushikago/hanamgri/schema.rb', line 8 def initialize(&block) @fields = [] instance_eval(&block) if block_given? end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
6 7 8 |
# File 'lib/mushikago/hanamgri/schema.rb', line 6 def fields @fields end |
Instance Method Details
#add(field_or_hash) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/mushikago/hanamgri/schema.rb', line 13 def add field_or_hash field = field_or_hash if field.kind_of?(Hash) field = Mushikago::Hanamgri::Field.new(field[:name], field[:required], field[:type], field[:knowledge_name]) end field.validate! @fields << field end |
#to_json(*args) ⇒ Object
22 23 24 |
# File 'lib/mushikago/hanamgri/schema.rb', line 22 def to_json *args {:fields => @fields}.to_json(args) end |