active_data 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/active_data.gemspec +1 -1
- data/lib/active_data/model/attributes.rb +4 -0
- data/lib/active_data/model/attributes/base.rb +7 -1
- data/lib/active_data/model/attributes/reflections/attribute.rb +4 -0
- data/lib/active_data/model/attributes/reflections/base.rb +1 -1
- data/lib/active_data/version.rb +1 -1
- data/spec/lib/active_data/model/attributes/base_spec.rb +8 -0
- data/spec/lib/active_data/model/attributes_spec.rb +2 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afec00097f73eb4a4e675f3f441c7c683b11b334dedec7eebc48670622770b50
|
4
|
+
data.tar.gz: afc5306ef42e04ff6c987a2e17065f8b7712dffef2975221296a1810b7501d78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 252757a6370421a428859eb88a88edd081683d5a7cb78f7e28cae40dff56681e2b5f4b9d37c438d6ba9959014259234fa6c2dc4d6325d2c2801718b1cd253f9c
|
7
|
+
data.tar.gz: a8c9449f1236d9b35e7e665c2f164a50635e5cdb2a3e8fbd6b5e803b422069b7589f6c380a424f64e2b629966a4c0bc0376774e68fc9c62e7199447daec249f5
|
data/CHANGELOG.md
CHANGED
data/active_data.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_development_dependency 'appraisal'
|
19
19
|
gem.add_development_dependency 'database_cleaner'
|
20
20
|
gem.add_development_dependency 'rake'
|
21
|
-
gem.add_development_dependency 'rspec'
|
21
|
+
gem.add_development_dependency 'rspec', '~> 3.7.0'
|
22
22
|
gem.add_development_dependency 'rspec-its'
|
23
23
|
gem.add_development_dependency 'rubocop', '0.52.1'
|
24
24
|
gem.add_development_dependency 'rubysl', '~> 2.0' if RUBY_ENGINE == 'rbx'
|
@@ -8,14 +8,16 @@ module ActiveData
|
|
8
8
|
def initialize(name, owner)
|
9
9
|
@name = name
|
10
10
|
@owner = owner
|
11
|
+
@origin = :default
|
11
12
|
end
|
12
13
|
|
13
14
|
def reflection
|
14
15
|
@owner.class._attributes[name]
|
15
16
|
end
|
16
17
|
|
17
|
-
def write_value(value)
|
18
|
+
def write_value(value, origin: :user)
|
18
19
|
reset
|
20
|
+
@origin = origin
|
19
21
|
@value_cache = value
|
20
22
|
end
|
21
23
|
|
@@ -36,6 +38,10 @@ module ActiveData
|
|
36
38
|
@value_cache
|
37
39
|
end
|
38
40
|
|
41
|
+
def came_from_user?
|
42
|
+
@origin == :user
|
43
|
+
end
|
44
|
+
|
39
45
|
def value_present?
|
40
46
|
!read.nil? && !(read.respond_to?(:empty?) && read.empty?)
|
41
47
|
end
|
@@ -26,7 +26,7 @@ module ActiveData
|
|
26
26
|
|
27
27
|
def build_attribute(owner, raw_value = ActiveData::UNDEFINED)
|
28
28
|
attribute = self.class.attribute_class.new(name, owner)
|
29
|
-
attribute.write_value(raw_value) unless raw_value == ActiveData::UNDEFINED
|
29
|
+
attribute.write_value(raw_value, origin: :persistence) unless raw_value == ActiveData::UNDEFINED
|
30
30
|
attribute
|
31
31
|
end
|
32
32
|
|
data/lib/active_data/version.rb
CHANGED
@@ -37,6 +37,14 @@ describe ActiveData::Model::Attributes::Base do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
describe '#came_from_user?' do
|
41
|
+
let(:field) { attribute(type: String, default: 'world') }
|
42
|
+
let(:object) { Object.new }
|
43
|
+
|
44
|
+
specify { expect(field.came_from_user?).to eq(false) }
|
45
|
+
specify { expect(field.tap { |r| r.write('value') }.came_from_user?).to eq(true) }
|
46
|
+
end
|
47
|
+
|
40
48
|
describe '#value_present?' do
|
41
49
|
let(:field) { attribute }
|
42
50
|
|
@@ -249,6 +249,7 @@ describe ActiveData::Model::Attributes do
|
|
249
249
|
its(:hello?) { should eq(false) }
|
250
250
|
its(:count) { should == 10 }
|
251
251
|
its(:count_before_type_cast) { should == '10' }
|
252
|
+
its(:count_came_from_user?) { should eq(false) }
|
252
253
|
its(:count?) { should eq(true) }
|
253
254
|
its(:calc) { should == 5 }
|
254
255
|
its(:enum?) { should eq(false) }
|
@@ -256,6 +257,7 @@ describe ActiveData::Model::Attributes do
|
|
256
257
|
specify { expect { subject.hello = 'worlds' }.to change { subject.hello }.from(nil).to('worlds') }
|
257
258
|
specify { expect { subject.count = 20 }.to change { subject.count }.from(10).to(20) }
|
258
259
|
specify { expect { subject.calc = 15 }.to change { subject.calc }.from(5).to(15) }
|
260
|
+
specify { expect { subject.count = '11' }.to change { subject.count_came_from_user? }.from(false).to(true) }
|
259
261
|
|
260
262
|
context 'enums' do
|
261
263
|
specify do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pyromaniac
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 3.7.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 3.7.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec-its
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|