Class: Super::Schema::Fields
- Inherits:
-
Object
- Object
- Super::Schema::Fields
- Includes:
- Enumerable
- Defined in:
- lib/super/schema.rb
Overview
This class can be thought of as a Hash, where the keys usually refer to
the model's column name and the value refers to the column type. Note
though that this isn't always the case—different SchemaTypes
can do
whatever makes sense in their context
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #delete(key) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(transform_value_on_set: nil) ⇒ Fields
constructor
A new instance of Fields.
- #keys ⇒ Object
- #nested ⇒ Object
- #replace(other) ⇒ Object
- #to_h ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(transform_value_on_set: nil) ⇒ Fields
Returns a new instance of Fields.
17 18 19 20 |
# File 'lib/super/schema.rb', line 17 def initialize(transform_value_on_set: nil) @backing = {} @transform_value_on_set = transform_value_on_set end |
Instance Method Details
#[](key) ⇒ Object
22 23 24 |
# File 'lib/super/schema.rb', line 22 def [](key) @backing[key] end |
#[]=(key, value) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/super/schema.rb', line 26 def []=(key, value) @backing[key] = if @transform_value_on_set @transform_value_on_set.call(value) else value end end |
#delete(key) ⇒ Object
51 52 53 |
# File 'lib/super/schema.rb', line 51 def delete(key) @backing.delete(key) end |
#each(&block) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/super/schema.rb', line 43 def each(&block) if block return @backing.each(&block) end enum_for(:each) end |
#keys ⇒ Object
35 36 37 |
# File 'lib/super/schema.rb', line 35 def keys @backing.keys end |
#nested ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/super/schema.rb', line 63 def nested outside = @backing inside = {} @backing = inside yield inside ensure @backing = outside inside end |
#replace(other) ⇒ Object
55 56 57 |
# File 'lib/super/schema.rb', line 55 def replace(other) @backing = other end |
#to_h ⇒ Object
59 60 61 |
# File 'lib/super/schema.rb', line 59 def to_h @backing end |
#values ⇒ Object
39 40 41 |
# File 'lib/super/schema.rb', line 39 def values @backing.values end |