Class: ActiveRecord::TypedStore::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/typed_store/dsl.rb

Constant Summary collapse

NO_DEFAULT_GIVEN =
Object.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute_name, options) {|_self| ... } ⇒ DSL

Returns a new instance of DSL.

Yields:

  • (_self)

Yield Parameters:



9
10
11
12
13
14
15
# File 'lib/active_record/typed_store/dsl.rb', line 9

def initialize(attribute_name, options)
  @coder = options.fetch(:coder) { default_coder(attribute_name) }
  @accessors = options[:accessors]
  @accessors = [] if options[:accessors] == false
  @fields = {}
  yield self
end

Instance Attribute Details

#coderObject (readonly)

Returns the value of attribute coder.



7
8
9
# File 'lib/active_record/typed_store/dsl.rb', line 7

def coder
  @coder
end

#fieldsObject (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

#accessorsObject



27
28
29
# File 'lib/active_record/typed_store/dsl.rb', line 27

def accessors
  @accessors || @fields.values.select(&:accessor).map(&:name)
end

#default_coder(attribute_name) ⇒ Object



18
19
20
# File 'lib/active_record/typed_store/dsl.rb', line 18

def default_coder(attribute_name)
  ActiveRecord::Coders::YAMLColumn.new
end