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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aec99c84b95cc5a79feaf4230cdbf4eb89780afc910bf03278d5f2377a48b0c5
4
- data.tar.gz: 71941c2fd303ccca637d7f58646dc5a3e3417f506e8cee405a57649a3c770d6c
3
+ metadata.gz: afec00097f73eb4a4e675f3f441c7c683b11b334dedec7eebc48670622770b50
4
+ data.tar.gz: afc5306ef42e04ff6c987a2e17065f8b7712dffef2975221296a1810b7501d78
5
5
  SHA512:
6
- metadata.gz: 3603d8b5de895f35f5c19db31a1de8fa71853595a0d93cf772c2894ff0a89fec0afb1d3b3c6f56b8d410ea22339f5e9abe96ca1023a1b414b720f1526afcc09e
7
- data.tar.gz: 35a90113764e1a5125d8cd205036e804e9dbfe7e2cb1ffdd812d6b99a5b0233c7efebafaab8452ef12d89c1a78f3d8ee212b55dd5ad59bbc8b399e80c256cbc8
6
+ metadata.gz: 252757a6370421a428859eb88a88edd081683d5a7cb78f7e28cae40dff56681e2b5f4b9d37c438d6ba9959014259234fa6c2dc4d6325d2c2801718b1cd253f9c
7
+ data.tar.gz: a8c9449f1236d9b35e7e665c2f164a50635e5cdb2a3e8fbd6b5e803b422069b7589f6c380a424f64e2b629966a4c0bc0376774e68fc9c62e7199447daec249f5
@@ -1,5 +1,11 @@
1
1
  # master
2
2
 
3
+ # Version 1.1.3
4
+
5
+ ## Changes
6
+
7
+ * `came_from_user?` attribute method (#65)
8
+
3
9
  # Version 1.1.2
4
10
 
5
11
  ## Changes
@@ -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'
@@ -141,6 +141,10 @@ module ActiveData
141
141
  attribute(name).read_before_type_cast
142
142
  end
143
143
 
144
+ def attribute_came_from_user?(name)
145
+ attribute(name).came_from_user?
146
+ end
147
+
144
148
  def attribute_present?(name)
145
149
  attribute(name).value_present?
146
150
  end
@@ -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
@@ -27,6 +27,10 @@ module ActiveData
27
27
  attribute('#{name}').read_before_type_cast
28
28
  end
29
29
 
30
+ def #{name}_came_from_user?
31
+ attribute('#{name}').came_from_user?
32
+ end
33
+
30
34
  def #{name}_default
31
35
  attribute('#{name}').default
32
36
  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
 
@@ -1,3 +1,3 @@
1
1
  module ActiveData
2
- VERSION = '1.1.2'.freeze
2
+ VERSION = '1.1.3'.freeze
3
3
  end
@@ -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.2
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-05-11 00:00:00.000000000 Z
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: '0'
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: '0'
82
+ version: 3.7.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec-its
85
85
  requirement: !ruby/object:Gem::Requirement