Class: ActiveRecord::TypedStore::DSL
- Inherits:
-
Object
- Object
- ActiveRecord::TypedStore::DSL
- Defined in:
- lib/active_record/typed_store/dsl.rb
Constant Summary collapse
- NO_DEFAULT_GIVEN =
Object.new
Instance Attribute Summary collapse
-
#coder ⇒ Object
readonly
Returns the value of attribute coder.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
- #accessors ⇒ Object
- #default_coder(attribute_name) ⇒ Object
-
#initialize(store_name, options) {|_self| ... } ⇒ DSL
constructor
A new instance of DSL.
Constructor Details
#initialize(store_name, options) {|_self| ... } ⇒ DSL
Returns a new instance of DSL.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/active_record/typed_store/dsl.rb', line 9 def initialize(store_name, ) @coder = .fetch(:coder) { default_coder(store_name) } @store_name = store_name @prefix = case [:prefix] when String, Symbol "#{[:prefix]}_" when true "#{store_name}_" when false, nil "" else raise ArgumentError, "Unexpected type for prefix option. Expected string, symbol, or boolean" end @suffix = case [:suffix] when String, Symbol "_#{[:suffix]}" when true "_#{store_name}" when false, nil "" else raise ArgumentError, "Unexpected type for suffix option. Expected string, symbol, or boolean" end @accessors = if [:accessors] == false {} elsif [:accessors].is_a?(Array) [:accessors].each_with_object({}) do |accessor_name, hash| hash[accessor_name] = accessor_key_for(accessor_name) end end @fields = {} yield self end |
Instance Attribute Details
#coder ⇒ Object (readonly)
Returns the value of attribute coder.
7 8 9 |
# File 'lib/active_record/typed_store/dsl.rb', line 7 def coder @coder end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
7 8 9 |
# File 'lib/active_record/typed_store/dsl.rb', line 7 def fields @fields end |
Instance Method Details
#accessors ⇒ Object
55 56 57 58 59 |
# File 'lib/active_record/typed_store/dsl.rb', line 55 def accessors @accessors || @fields.values.select(&:accessor).each_with_object({}) do |field, hash| hash[field.name] = accessor_key_for(field.name) end end |
#default_coder(attribute_name) ⇒ Object
46 47 48 |
# File 'lib/active_record/typed_store/dsl.rb', line 46 def default_coder(attribute_name) ActiveRecord::Coders::YAMLColumn.new end |