Class: Dacs::Schema
- Inherits:
-
Object
- Object
- Dacs::Schema
- Defined in:
- lib/dacs/schema.rb
Instance Method Summary collapse
- #default_value(key) ⇒ Object
- #defaults ⇒ Object
- #defined?(key) ⇒ Boolean
-
#key(name, options = {}) ⇒ Object
Add a key definition.
- #keys ⇒ Object
- #optional?(key) ⇒ Boolean
- #required?(key) ⇒ Boolean
Instance Method Details
#default_value(key) ⇒ Object
27 28 29 30 |
# File 'lib/dacs/schema.rb', line 27 def default_value(key) assert_key_defined!(key) key_def(key.to_s)[:default] end |
#defaults ⇒ Object
32 33 34 35 36 37 |
# File 'lib/dacs/schema.rb', line 32 def defaults key_defs.inject({}) { |h, key_def| h[key_def[:name]] = key_def[:default] if key_def.key?(:default) h } end |
#defined?(key) ⇒ Boolean
23 24 25 |
# File 'lib/dacs/schema.rb', line 23 def defined?(key) !!key_def(key) end |
#key(name, options = {}) ⇒ Object
Add a key definition
5 6 7 |
# File 'lib/dacs/schema.rb', line 5 def key(name, ={}) key_defs << { :name => name.to_s }.merge() end |
#keys ⇒ Object
9 10 11 |
# File 'lib/dacs/schema.rb', line 9 def keys key_defs.map{|d| d[:name]} end |
#optional?(key) ⇒ Boolean
19 20 21 |
# File 'lib/dacs/schema.rb', line 19 def optional?(key) !required?(key.to_s) end |
#required?(key) ⇒ Boolean
13 14 15 16 17 |
# File 'lib/dacs/schema.rb', line 13 def required?(key) assert_key_defined!(key) kd = key_def(key.to_s) kd && !kd.key?(:default) end |