active_data 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.rspec +0 -1
- data/.rvmrc +1 -1
- data/.travis.yml +13 -6
- data/Appraisals +7 -0
- data/Gemfile +1 -5
- data/Guardfile +68 -15
- data/README.md +144 -2
- data/active_data.gemspec +19 -11
- data/gemfiles/rails.4.0.gemfile +14 -0
- data/gemfiles/rails.4.1.gemfile +14 -0
- data/gemfiles/rails.4.2.gemfile +14 -0
- data/gemfiles/rails.5.0.gemfile +14 -0
- data/lib/active_data.rb +120 -3
- data/lib/active_data/active_record/associations.rb +50 -0
- data/lib/active_data/active_record/nested_attributes.rb +24 -0
- data/lib/active_data/config.rb +40 -0
- data/lib/active_data/errors.rb +93 -0
- data/lib/active_data/extensions.rb +33 -0
- data/lib/active_data/model.rb +16 -74
- data/lib/active_data/model/associations.rb +84 -15
- data/lib/active_data/model/associations/base.rb +79 -0
- data/lib/active_data/model/associations/collection/embedded.rb +12 -0
- data/lib/active_data/model/associations/collection/proxy.rb +32 -0
- data/lib/active_data/model/associations/collection/referenced.rb +26 -0
- data/lib/active_data/model/associations/embeds_many.rb +124 -18
- data/lib/active_data/model/associations/embeds_one.rb +90 -15
- data/lib/active_data/model/associations/nested_attributes.rb +180 -0
- data/lib/active_data/model/associations/references_many.rb +96 -0
- data/lib/active_data/model/associations/references_one.rb +83 -0
- data/lib/active_data/model/associations/reflections/base.rb +100 -0
- data/lib/active_data/model/associations/reflections/embeds_many.rb +25 -0
- data/lib/active_data/model/associations/reflections/embeds_one.rb +49 -0
- data/lib/active_data/model/associations/reflections/reference_reflection.rb +45 -0
- data/lib/active_data/model/associations/reflections/references_many.rb +28 -0
- data/lib/active_data/model/associations/reflections/references_one.rb +28 -0
- data/lib/active_data/model/associations/validations.rb +63 -0
- data/lib/active_data/model/attributes.rb +247 -0
- data/lib/active_data/model/attributes/attribute.rb +73 -0
- data/lib/active_data/model/attributes/base.rb +116 -0
- data/lib/active_data/model/attributes/collection.rb +17 -0
- data/lib/active_data/model/attributes/dictionary.rb +26 -0
- data/lib/active_data/model/attributes/localized.rb +42 -0
- data/lib/active_data/model/attributes/reference_many.rb +21 -0
- data/lib/active_data/model/attributes/reference_one.rb +42 -0
- data/lib/active_data/model/attributes/reflections/attribute.rb +55 -0
- data/lib/active_data/model/attributes/reflections/base.rb +62 -0
- data/lib/active_data/model/attributes/reflections/collection.rb +10 -0
- data/lib/active_data/model/attributes/reflections/dictionary.rb +13 -0
- data/lib/active_data/model/attributes/reflections/localized.rb +43 -0
- data/lib/active_data/model/attributes/reflections/reference_many.rb +10 -0
- data/lib/active_data/model/attributes/reflections/reference_one.rb +58 -0
- data/lib/active_data/model/attributes/reflections/represents.rb +55 -0
- data/lib/active_data/model/attributes/represents.rb +64 -0
- data/lib/active_data/model/callbacks.rb +71 -0
- data/lib/active_data/model/conventions.rb +35 -0
- data/lib/active_data/model/dirty.rb +77 -0
- data/lib/active_data/model/lifecycle.rb +307 -0
- data/lib/active_data/model/localization.rb +21 -0
- data/lib/active_data/model/persistence.rb +57 -0
- data/lib/active_data/model/primary.rb +51 -0
- data/lib/active_data/model/scopes.rb +77 -0
- data/lib/active_data/model/validations.rb +27 -0
- data/lib/active_data/model/validations/associated.rb +19 -0
- data/lib/active_data/model/validations/nested.rb +39 -0
- data/lib/active_data/railtie.rb +7 -0
- data/lib/active_data/version.rb +1 -1
- data/spec/lib/active_data/active_record/associations_spec.rb +149 -0
- data/spec/lib/active_data/active_record/nested_attributes_spec.rb +16 -0
- data/spec/lib/active_data/config_spec.rb +44 -0
- data/spec/lib/active_data/model/associations/embeds_many_spec.rb +362 -52
- data/spec/lib/active_data/model/associations/embeds_one_spec.rb +250 -31
- data/spec/lib/active_data/model/associations/nested_attributes_spec.rb +23 -0
- data/spec/lib/active_data/model/associations/references_many_spec.rb +196 -0
- data/spec/lib/active_data/model/associations/references_one_spec.rb +134 -0
- data/spec/lib/active_data/model/associations/reflections/embeds_many_spec.rb +144 -0
- data/spec/lib/active_data/model/associations/reflections/embeds_one_spec.rb +116 -0
- data/spec/lib/active_data/model/associations/reflections/references_many_spec.rb +255 -0
- data/spec/lib/active_data/model/associations/reflections/references_one_spec.rb +208 -0
- data/spec/lib/active_data/model/associations/validations_spec.rb +153 -0
- data/spec/lib/active_data/model/associations_spec.rb +189 -0
- data/spec/lib/active_data/model/attributes/attribute_spec.rb +144 -0
- data/spec/lib/active_data/model/attributes/base_spec.rb +82 -0
- data/spec/lib/active_data/model/attributes/collection_spec.rb +73 -0
- data/spec/lib/active_data/model/attributes/dictionary_spec.rb +93 -0
- data/spec/lib/active_data/model/attributes/localized_spec.rb +88 -33
- data/spec/lib/active_data/model/attributes/reflections/attribute_spec.rb +72 -0
- data/spec/lib/active_data/model/attributes/reflections/base_spec.rb +56 -0
- data/spec/lib/active_data/model/attributes/reflections/collection_spec.rb +37 -0
- data/spec/lib/active_data/model/attributes/reflections/dictionary_spec.rb +43 -0
- data/spec/lib/active_data/model/attributes/reflections/localized_spec.rb +37 -0
- data/spec/lib/active_data/model/attributes/reflections/represents_spec.rb +70 -0
- data/spec/lib/active_data/model/attributes/represents_spec.rb +153 -0
- data/spec/lib/active_data/model/attributes_spec.rb +243 -0
- data/spec/lib/active_data/model/callbacks_spec.rb +338 -0
- data/spec/lib/active_data/model/conventions_spec.rb +12 -0
- data/spec/lib/active_data/model/dirty_spec.rb +75 -0
- data/spec/lib/active_data/model/lifecycle_spec.rb +330 -0
- data/spec/lib/active_data/model/nested_attributes.rb +202 -0
- data/spec/lib/active_data/model/persistence_spec.rb +47 -0
- data/spec/lib/active_data/model/primary_spec.rb +84 -0
- data/spec/lib/active_data/model/scopes_spec.rb +88 -0
- data/spec/lib/active_data/model/typecasting_spec.rb +192 -0
- data/spec/lib/active_data/model/validations/associated_spec.rb +94 -0
- data/spec/lib/active_data/model/validations/nested_spec.rb +93 -0
- data/spec/lib/active_data/model/validations_spec.rb +31 -0
- data/spec/lib/active_data/model_spec.rb +1 -32
- data/spec/lib/active_data_spec.rb +12 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/support/model_helpers.rb +10 -0
- metadata +246 -54
- data/gemfiles/Gemfile.rails-3 +0 -14
- data/lib/active_data/attributes/base.rb +0 -69
- data/lib/active_data/attributes/localized.rb +0 -42
- data/lib/active_data/model/associations/association.rb +0 -30
- data/lib/active_data/model/attributable.rb +0 -122
- data/lib/active_data/model/collectionizable.rb +0 -55
- data/lib/active_data/model/collectionizable/proxy.rb +0 -42
- data/lib/active_data/model/extensions.rb +0 -9
- data/lib/active_data/model/extensions/array.rb +0 -24
- data/lib/active_data/model/extensions/big_decimal.rb +0 -17
- data/lib/active_data/model/extensions/boolean.rb +0 -38
- data/lib/active_data/model/extensions/date.rb +0 -17
- data/lib/active_data/model/extensions/date_time.rb +0 -17
- data/lib/active_data/model/extensions/float.rb +0 -17
- data/lib/active_data/model/extensions/hash.rb +0 -22
- data/lib/active_data/model/extensions/integer.rb +0 -17
- data/lib/active_data/model/extensions/localized.rb +0 -22
- data/lib/active_data/model/extensions/object.rb +0 -17
- data/lib/active_data/model/extensions/string.rb +0 -17
- data/lib/active_data/model/extensions/time.rb +0 -17
- data/lib/active_data/model/localizable.rb +0 -31
- data/lib/active_data/model/nested_attributes.rb +0 -58
- data/lib/active_data/model/parameterizable.rb +0 -29
- data/lib/active_data/validations.rb +0 -7
- data/lib/active_data/validations/associated.rb +0 -17
- data/spec/lib/active_data/model/attributable_spec.rb +0 -191
- data/spec/lib/active_data/model/collectionizable_spec.rb +0 -60
- data/spec/lib/active_data/model/nested_attributes_spec.rb +0 -67
- data/spec/lib/active_data/model/type_cast_spec.rb +0 -116
- data/spec/lib/active_data/validations/associated_spec.rb +0 -88
@@ -0,0 +1,17 @@
|
|
1
|
+
module ActiveData
|
2
|
+
module Model
|
3
|
+
module Attributes
|
4
|
+
class Collection < Attribute
|
5
|
+
def read
|
6
|
+
@value ||= normalize(read_before_type_cast.map do |value|
|
7
|
+
enumerize(typecast(value))
|
8
|
+
end)
|
9
|
+
end
|
10
|
+
|
11
|
+
def read_before_type_cast
|
12
|
+
@value_before_type_cast ||= Array.wrap(@value_cache).map { |value| defaultize(value) }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ActiveData
|
2
|
+
module Model
|
3
|
+
module Attributes
|
4
|
+
class Dictionary < Attribute
|
5
|
+
delegate :keys, to: :reflection
|
6
|
+
|
7
|
+
def read
|
8
|
+
@value ||= begin
|
9
|
+
hash = read_before_type_cast
|
10
|
+
hash = hash.stringify_keys.slice(*keys) if keys.present?
|
11
|
+
|
12
|
+
normalize(Hash[hash.map do |key, value|
|
13
|
+
[key, enumerize(typecast(value))]
|
14
|
+
end].with_indifferent_access).with_indifferent_access
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def read_before_type_cast
|
19
|
+
@value_before_type_cast ||= Hash[(@value_cache.presence || {}).map do |key, value|
|
20
|
+
[key, defaultize(value)]
|
21
|
+
end].with_indifferent_access
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ActiveData
|
2
|
+
module Model
|
3
|
+
module Attributes
|
4
|
+
class Localized < Attribute
|
5
|
+
def read
|
6
|
+
@value ||= Hash[read_before_type_cast.map do |locale, value|
|
7
|
+
[locale.to_s, normalize(enumerize(typecast(value)))]
|
8
|
+
end]
|
9
|
+
end
|
10
|
+
|
11
|
+
def read_before_type_cast
|
12
|
+
@value_before_type_cast ||= Hash[(@value_cache.presence || {}).map do |locale, value|
|
13
|
+
[locale.to_s, defaultize(value)]
|
14
|
+
end]
|
15
|
+
end
|
16
|
+
|
17
|
+
def write_locale value, locale
|
18
|
+
pollute do
|
19
|
+
write(read.merge(locale.to_s => value))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def read_locale locale
|
24
|
+
read[owner.class.fallbacks(locale).detect do |fallback|
|
25
|
+
read[fallback.to_s]
|
26
|
+
end.to_s]
|
27
|
+
end
|
28
|
+
|
29
|
+
def read_locale_before_type_cast locale
|
30
|
+
read_before_type_cast[owner.class.fallbacks(locale).detect do |fallback|
|
31
|
+
read_before_type_cast[fallback.to_s]
|
32
|
+
end.to_s]
|
33
|
+
end
|
34
|
+
|
35
|
+
def locale_query locale
|
36
|
+
value = read_locale(locale)
|
37
|
+
!(value.respond_to?(:zero?) ? value.zero? : value.blank?)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActiveData
|
2
|
+
module Model
|
3
|
+
module Attributes
|
4
|
+
class ReferenceMany < ReferenceOne
|
5
|
+
def read_before_type_cast
|
6
|
+
variable_cache(:value_before_type_cast) do
|
7
|
+
Array.wrap(@value_cache)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def type_casted_value
|
14
|
+
variable_cache(:value) do
|
15
|
+
read_before_type_cast.map { |id| typecast(id) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ActiveData
|
2
|
+
module Model
|
3
|
+
module Attributes
|
4
|
+
class ReferenceOne < Base
|
5
|
+
def write value
|
6
|
+
pollute do
|
7
|
+
previous = type_casted_value
|
8
|
+
result = write_value value
|
9
|
+
if (!value.nil? && type_casted_value.nil?) || type_casted_value != previous
|
10
|
+
association.reset
|
11
|
+
end
|
12
|
+
result
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def read
|
17
|
+
if association.target
|
18
|
+
association.identify
|
19
|
+
else
|
20
|
+
type_casted_value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def read_before_type_cast
|
25
|
+
@value_cache
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def type_casted_value
|
31
|
+
variable_cache(:value) do
|
32
|
+
typecast(read_before_type_cast)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def association
|
37
|
+
@association ||= owner.association(reflection.association)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ActiveData
|
2
|
+
module Model
|
3
|
+
module Attributes
|
4
|
+
module Reflections
|
5
|
+
class Attribute < Base
|
6
|
+
def self.build target, generated_methods, name, *args, &block
|
7
|
+
attribute = super(target, generated_methods, name, *args, &block)
|
8
|
+
generate_methods name, generated_methods
|
9
|
+
attribute
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.generate_methods name, target
|
13
|
+
target.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
14
|
+
def #{name}
|
15
|
+
attribute('#{name}').read
|
16
|
+
end
|
17
|
+
|
18
|
+
def #{name}= value
|
19
|
+
attribute('#{name}').write(value)
|
20
|
+
end
|
21
|
+
|
22
|
+
def #{name}?
|
23
|
+
attribute('#{name}').query
|
24
|
+
end
|
25
|
+
|
26
|
+
def #{name}_before_type_cast
|
27
|
+
attribute('#{name}').read_before_type_cast
|
28
|
+
end
|
29
|
+
|
30
|
+
def #{name}_default
|
31
|
+
attribute('#{name}').default
|
32
|
+
end
|
33
|
+
|
34
|
+
def #{name}_values
|
35
|
+
attribute('#{name}').enum.to_a
|
36
|
+
end
|
37
|
+
RUBY
|
38
|
+
end
|
39
|
+
|
40
|
+
def defaultizer
|
41
|
+
@defaultizer ||= options[:default]
|
42
|
+
end
|
43
|
+
|
44
|
+
def enumerizer
|
45
|
+
@enumerizer ||= options[:enum] || options[:in]
|
46
|
+
end
|
47
|
+
|
48
|
+
def normalizers
|
49
|
+
@normalizers ||= Array.wrap(options[:normalize] || options[:normalizer] || options[:normalizers])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module ActiveData
|
2
|
+
module Model
|
3
|
+
module Attributes
|
4
|
+
module Reflections
|
5
|
+
class Base
|
6
|
+
attr_reader :name, :options
|
7
|
+
class << self
|
8
|
+
def build target, generated_methods, name, *args, &block
|
9
|
+
options = args.extract_options!
|
10
|
+
options.merge!(type: args.first) if args.first
|
11
|
+
options.merge!(default: block) if block
|
12
|
+
new(name, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def generate_methods name, target
|
16
|
+
end
|
17
|
+
|
18
|
+
def attribute_class
|
19
|
+
@attribute_class ||= "ActiveData::Model::Attributes::#{name.demodulize}".constantize
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize name, options = {}
|
24
|
+
@name = name.to_s
|
25
|
+
@options = options
|
26
|
+
end
|
27
|
+
|
28
|
+
def build_attribute owner, raw_value = nil
|
29
|
+
attribute = self.class.attribute_class.new(name, owner)
|
30
|
+
attribute.write_value(raw_value) if raw_value
|
31
|
+
attribute
|
32
|
+
end
|
33
|
+
|
34
|
+
def type
|
35
|
+
@type ||= case options[:type]
|
36
|
+
when Proc
|
37
|
+
options[:type].call
|
38
|
+
when Class
|
39
|
+
options[:type]
|
40
|
+
when nil
|
41
|
+
raise "Type is not specified for `#{name}`"
|
42
|
+
else
|
43
|
+
options[:type].to_s.camelize.constantize
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def typecaster
|
48
|
+
@typecaster ||= ActiveData.typecaster(type.ancestors.grep(Class))
|
49
|
+
end
|
50
|
+
|
51
|
+
def readonly
|
52
|
+
@readonly ||= options[:readonly]
|
53
|
+
end
|
54
|
+
|
55
|
+
def inspect_reflection
|
56
|
+
"#{name}: #{type}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module ActiveData
|
2
|
+
module Model
|
3
|
+
module Attributes
|
4
|
+
module Reflections
|
5
|
+
class Localized < Attribute
|
6
|
+
def self.build target, generated_methods, name, *args, &block
|
7
|
+
attribute = super(target, generated_methods, name, *args, &block)
|
8
|
+
generate_methods name, generated_methods
|
9
|
+
attribute
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.generate_methods name, target
|
13
|
+
target.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
14
|
+
def #{name}_translations
|
15
|
+
attribute('#{name}').read
|
16
|
+
end
|
17
|
+
|
18
|
+
def #{name}_translations= value
|
19
|
+
attribute('#{name}').write(value)
|
20
|
+
end
|
21
|
+
|
22
|
+
def #{name}
|
23
|
+
attribute('#{name}').read_locale(self.class.locale)
|
24
|
+
end
|
25
|
+
|
26
|
+
def #{name}= value
|
27
|
+
attribute('#{name}').write_locale(value, self.class.locale)
|
28
|
+
end
|
29
|
+
|
30
|
+
def #{name}?
|
31
|
+
attribute('#{name}').locale_query(self.class.locale)
|
32
|
+
end
|
33
|
+
|
34
|
+
def #{name}_before_type_cast
|
35
|
+
attribute('#{name}').read_locale_before_type_cast(self.class.locale)
|
36
|
+
end
|
37
|
+
RUBY
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module ActiveData
|
2
|
+
module Model
|
3
|
+
module Attributes
|
4
|
+
module Reflections
|
5
|
+
class ReferenceOne < Base
|
6
|
+
TYPES = {
|
7
|
+
integer: Integer,
|
8
|
+
float: Float,
|
9
|
+
decimal: BigDecimal,
|
10
|
+
datetime: Time,
|
11
|
+
timestamp: Time,
|
12
|
+
time: Time,
|
13
|
+
date: Date,
|
14
|
+
text: String,
|
15
|
+
string: String,
|
16
|
+
binary: String,
|
17
|
+
boolean: Boolean
|
18
|
+
}
|
19
|
+
|
20
|
+
def self.build target, generated_methods, name, *args, &block
|
21
|
+
options = args.extract_options!
|
22
|
+
generate_methods name, generated_methods
|
23
|
+
type_proc = -> {
|
24
|
+
reflection = target.reflect_on_association(options[:association])
|
25
|
+
column = reflection.klass.columns_hash[reflection.primary_key.to_s]
|
26
|
+
TYPES[column.type]
|
27
|
+
}
|
28
|
+
new(name, options.reverse_merge(type: type_proc))
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.generate_methods name, target
|
32
|
+
target.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
33
|
+
def #{name}
|
34
|
+
attribute('#{name}').read
|
35
|
+
end
|
36
|
+
|
37
|
+
def #{name}= value
|
38
|
+
attribute('#{name}').write(value)
|
39
|
+
end
|
40
|
+
|
41
|
+
def #{name}?
|
42
|
+
attribute('#{name}').query
|
43
|
+
end
|
44
|
+
|
45
|
+
def #{name}_before_type_cast
|
46
|
+
attribute('#{name}').read_before_type_cast
|
47
|
+
end
|
48
|
+
RUBY
|
49
|
+
end
|
50
|
+
|
51
|
+
def association
|
52
|
+
@association ||= options[:association].to_s
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ActiveData
|
2
|
+
module Model
|
3
|
+
module Attributes
|
4
|
+
module Reflections
|
5
|
+
class Represents < Attribute
|
6
|
+
def self.build target, generated_methods, name, *args, &block
|
7
|
+
options = args.extract_options!
|
8
|
+
|
9
|
+
reference = target.reflect_on_association(options[:of]) if target.respond_to?(:reflect_on_association)
|
10
|
+
reference ||= target.reflect_on_attribute(options[:of]) if target.respond_to?(:reflect_on_attribute)
|
11
|
+
if reference
|
12
|
+
options[:of] = reference.name
|
13
|
+
target.validates_nested options[:of]
|
14
|
+
end
|
15
|
+
|
16
|
+
super(target, generated_methods, name, *args, options, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize name, options
|
20
|
+
super
|
21
|
+
raise ArgumentError, "Undefined reference for `#{name}`" if reference.blank?
|
22
|
+
end
|
23
|
+
|
24
|
+
def type
|
25
|
+
Object
|
26
|
+
end
|
27
|
+
|
28
|
+
def reference
|
29
|
+
@reference ||= options[:of].to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def column
|
33
|
+
@column ||= options[:column].presence.try(:to_s) || name
|
34
|
+
end
|
35
|
+
|
36
|
+
def reader
|
37
|
+
@reader ||= options[:reader].presence.try(:to_s) || column
|
38
|
+
end
|
39
|
+
|
40
|
+
def reader_before_type_cast
|
41
|
+
@reader_before_type_cast ||= "#{reader}_before_type_cast"
|
42
|
+
end
|
43
|
+
|
44
|
+
def writer
|
45
|
+
@writer ||= "#{options[:writer].presence || column}="
|
46
|
+
end
|
47
|
+
|
48
|
+
def inspect_reflection
|
49
|
+
"#{name}: (represents)"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|