duck_record 0.0.9.1 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +13 -13
- data/lib/duck_record/associations/association.rb +15 -15
- data/lib/duck_record/associations/collection_association.rb +8 -8
- data/lib/duck_record/associations/collection_proxy.rb +1 -1
- data/lib/duck_record/associations/has_many_association.rb +0 -1
- data/lib/duck_record/associations/singular_association.rb +6 -6
- data/lib/duck_record/attribute/user_provided_default.rb +2 -2
- data/lib/duck_record/attribute.rb +70 -70
- data/lib/duck_record/attribute_assignment.rb +74 -74
- data/lib/duck_record/attribute_methods/before_type_cast.rb +9 -9
- data/lib/duck_record/attribute_methods/dirty.rb +29 -29
- data/lib/duck_record/attribute_methods/read.rb +27 -27
- data/lib/duck_record/attribute_methods/write.rb +20 -20
- data/lib/duck_record/attribute_methods.rb +8 -8
- data/lib/duck_record/attribute_mutation_tracker.rb +4 -4
- data/lib/duck_record/attribute_set/yaml_encoder.rb +5 -5
- data/lib/duck_record/attribute_set.rb +5 -5
- data/lib/duck_record/attributes.rb +14 -14
- data/lib/duck_record/base.rb +18 -18
- data/lib/duck_record/callbacks.rb +1 -1
- data/lib/duck_record/core.rb +35 -35
- data/lib/duck_record/inheritance.rb +25 -25
- data/lib/duck_record/model_schema.rb +10 -11
- data/lib/duck_record/nested_attributes.rb +149 -149
- data/lib/duck_record/reflection.rb +14 -14
- data/lib/duck_record/type/array.rb +6 -6
- data/lib/duck_record/type/registry.rb +21 -21
- data/lib/duck_record/type/serialized.rb +8 -8
- data/lib/duck_record/type/time.rb +0 -1
- data/lib/duck_record/type/unsigned_integer.rb +6 -6
- data/lib/duck_record/type.rb +16 -14
- data/lib/duck_record/validations/uniqueness_on_real_record.rb +45 -45
- data/lib/duck_record/validations.rb +6 -6
- data/lib/duck_record/version.rb +1 -1
- data/lib/duck_record.rb +7 -7
- metadata +7 -6
@@ -12,9 +12,9 @@ module DuckRecord
|
|
12
12
|
end
|
13
13
|
|
14
14
|
@finder_class = if options[:class_name].present?
|
15
|
-
|
15
|
+
options[:class_name].safe_constantize
|
16
16
|
elsif options[:class].present? && options[:class].is_a?(Class)
|
17
|
-
|
17
|
+
options[:class]
|
18
18
|
else
|
19
19
|
nil
|
20
20
|
end
|
@@ -59,58 +59,58 @@ module DuckRecord
|
|
59
59
|
|
60
60
|
protected
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
# the attribute may be an aliased attribute
|
69
|
-
if klass.attribute_alias?(attribute)
|
70
|
-
attribute = klass.attribute_alias(attribute)
|
71
|
-
end
|
62
|
+
def build_relation(klass, table, attribute, value) #:nodoc:
|
63
|
+
if reflection = klass._reflect_on_association(attribute)
|
64
|
+
attribute = reflection.foreign_key
|
65
|
+
value = value.attributes[reflection.klass.primary_key] unless value.nil?
|
66
|
+
end
|
72
67
|
|
73
|
-
|
68
|
+
# the attribute may be an aliased attribute
|
69
|
+
if klass.attribute_alias?(attribute)
|
70
|
+
attribute = klass.attribute_alias(attribute)
|
71
|
+
end
|
74
72
|
|
75
|
-
|
76
|
-
cast_type = klass.type_for_attribute(attribute_name)
|
77
|
-
value = cast_type.serialize(value)
|
78
|
-
value = klass.connection.type_cast(value)
|
73
|
+
attribute_name = attribute.to_s
|
79
74
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
klass.connection.case_sensitive_comparison(table, attribute, column, value)
|
85
|
-
end
|
86
|
-
if value.nil?
|
87
|
-
klass.unscoped.where(comparison)
|
88
|
-
else
|
89
|
-
bind = ActiveRecord::Relation::QueryAttribute.new(attribute_name, value, ActiveRecord::Type::Value.new)
|
90
|
-
klass.unscoped.where(comparison, bind)
|
91
|
-
end
|
92
|
-
rescue RangeError
|
93
|
-
klass.none
|
94
|
-
end
|
75
|
+
column = klass.columns_hash[attribute_name]
|
76
|
+
cast_type = klass.type_for_attribute(attribute_name)
|
77
|
+
value = cast_type.serialize(value)
|
78
|
+
value = klass.connection.type_cast(value)
|
95
79
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
record.association(scope_item).reader
|
80
|
+
comparison = if !options[:case_sensitive] && !value.nil?
|
81
|
+
# will use SQL LOWER function before comparison, unless it detects a case insensitive collation
|
82
|
+
klass.connection.case_insensitive_comparison(table, attribute, column, value)
|
100
83
|
else
|
101
|
-
|
84
|
+
klass.connection.case_sensitive_comparison(table, attribute, column, value)
|
102
85
|
end
|
103
|
-
|
86
|
+
if value.nil?
|
87
|
+
klass.unscoped.where(comparison)
|
88
|
+
else
|
89
|
+
bind = ActiveRecord::Relation::QueryAttribute.new(attribute_name, value, ActiveRecord::Type::Value.new)
|
90
|
+
klass.unscoped.where(comparison, bind)
|
91
|
+
end
|
92
|
+
rescue RangeError
|
93
|
+
klass.none
|
104
94
|
end
|
105
95
|
|
106
|
-
relation
|
107
|
-
|
96
|
+
def scope_relation(record, table, relation)
|
97
|
+
Array(options[:scope]).each do |scope_item|
|
98
|
+
scope_value = if record.class._reflect_on_association(scope_item)
|
99
|
+
record.association(scope_item).reader
|
100
|
+
else
|
101
|
+
record._read_attribute(scope_item)
|
102
|
+
end
|
103
|
+
relation = relation.where(scope_item => scope_value)
|
104
|
+
end
|
108
105
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
value
|
113
|
-
|
106
|
+
relation
|
107
|
+
end
|
108
|
+
|
109
|
+
def map_enum_attribute(klass, attribute, value)
|
110
|
+
mapping = klass.defined_enums[attribute.to_s]
|
111
|
+
value = mapping[value] if value && mapping
|
112
|
+
value
|
113
|
+
end
|
114
114
|
end
|
115
115
|
|
116
116
|
module ClassMethods
|
@@ -31,12 +31,12 @@ module DuckRecord
|
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
def default_validation_context
|
35
|
+
:default
|
36
|
+
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
def perform_validations(options = {})
|
39
|
+
options[:validate] == false || valid?(options[:context])
|
40
|
+
end
|
41
41
|
end
|
42
42
|
end
|
data/lib/duck_record/version.rb
CHANGED
data/lib/duck_record.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/rails"
|
3
|
+
require "active_model"
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
5
|
+
require "duck_record/type"
|
6
|
+
require "duck_record/attribute_set"
|
7
7
|
|
8
8
|
module DuckRecord
|
9
9
|
extend ActiveSupport::Autoload
|
@@ -22,7 +22,7 @@ module DuckRecord
|
|
22
22
|
autoload :Validations
|
23
23
|
|
24
24
|
eager_autoload do
|
25
|
-
autoload :DuckRecordError,
|
25
|
+
autoload :DuckRecordError, "duck_record/errors"
|
26
26
|
|
27
27
|
autoload :Associations
|
28
28
|
autoload :AttributeAssignment
|
@@ -50,5 +50,5 @@ module DuckRecord
|
|
50
50
|
end
|
51
51
|
|
52
52
|
ActiveSupport.on_load(:i18n) do
|
53
|
-
I18n.load_path << File.dirname(__FILE__) +
|
53
|
+
I18n.load_path << File.dirname(__FILE__) + "/duck_record/locale/en.yml"
|
54
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duck_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jasl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -66,10 +66,11 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
description: |-
|
70
|
+
It looks like Active Record and quacks like Active Record, but it can't do persistence or querying,
|
71
|
+
it's Duck Record!
|
72
|
+
Actually it's extract from Active Record.
|
73
|
+
Used for creating virtual models like ActiveType or ModelAttribute does.
|
73
74
|
email:
|
74
75
|
- jasl9187@hotmail.com
|
75
76
|
executables: []
|