Class: Leafy::Schema
Class Method Summary collapse
Instance Method Summary collapse
- #[](identifier) ⇒ Object
- #each ⇒ Object
- #ids ⇒ Object
-
#initialize(fields = []) ⇒ Schema
constructor
A new instance of Schema.
- #push(field) ⇒ Object (also: #<<)
- #serializable_hash ⇒ Object
Constructor Details
Class Method Details
.dump(schema) ⇒ Object
37 38 39 |
# File 'lib/leafy/schema.rb', line 37 def self.dump(schema) JSON.dump(schema.serializable_hash) end |
Instance Method Details
#[](identifier) ⇒ Object
24 25 26 |
# File 'lib/leafy/schema.rb', line 24 def [](identifier) @fields.find { |f| f.id == identifier } end |
#each ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/leafy/schema.rb', line 8 def each if block_given? @fields.each { |i| yield i } else @fields.each end end |
#ids ⇒ Object
20 21 22 |
# File 'lib/leafy/schema.rb', line 20 def ids @fields.map(&:id) end |
#push(field) ⇒ Object Also known as: <<
28 29 30 31 |
# File 'lib/leafy/schema.rb', line 28 def push(field) raise(ArgumentError, "is not a field") unless field.is_a?(Leafy::Field) @fields << field end |
#serializable_hash ⇒ Object
33 34 35 |
# File 'lib/leafy/schema.rb', line 33 def serializable_hash @fields.map(&:serializable_hash) end |