class ActiveRecord::TypedStore::DSL
Constants
- NO_DEFAULT_GIVEN
Attributes
coder[R]
fields[R]
Public Class Methods
new(store_name, options) { |self| ... }
click to toggle source
# File lib/active_record/typed_store/dsl.rb, line 9 def initialize(store_name, options) @coder = options.fetch(:coder) { default_coder(store_name) } @store_name = store_name @prefix = case options[:prefix] when String, Symbol "#{options[:prefix]}_" when true "#{store_name}_" when false, nil "" else raise ArgumentError, "Unexpected type for prefix option. Expected string, symbol, or boolean" end @suffix = case options[:suffix] when String, Symbol "_#{options[:suffix]}" when true "_#{store_name}" when false, nil "" else raise ArgumentError, "Unexpected type for suffix option. Expected string, symbol, or boolean" end @accessors = if options[:accessors] == false {} elsif options[:accessors].is_a?(Array) options[:accessors].each_with_object({}) do |accessor_name, hash| hash[accessor_name] = accessor_key_for(accessor_name) end end @fields = {} yield self end
Public Instance Methods
accessors()
click to toggle source
# 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)
click to toggle source
# File lib/active_record/typed_store/dsl.rb, line 46 def default_coder(attribute_name) ActiveRecord::Coders::YAMLColumn.new end
Private Instance Methods
accessor_key_for(name)
click to toggle source
# File lib/active_record/typed_store/dsl.rb, line 73 def accessor_key_for(name) "#{@prefix}#{name}#{@suffix}" end