hoodoo 1.2.2 → 1.2.3
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 +8 -8
- data/lib/hoodoo/active/active_record/creator.rb +7 -6
- data/lib/hoodoo/active/active_record/dated.rb +5 -5
- data/lib/hoodoo/active/active_record/manually_dated.rb +32 -7
- data/lib/hoodoo/version.rb +1 -1
- data/spec/active/active_record/creator_spec.rb +50 -6
- data/spec/active/active_record/dated_spec.rb +6 -0
- data/spec/active/active_record/manually_dated_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDRkMTlhM2I2NjQyNWE2OTQxZDA3MjdiMjQ2MjgzMzVkYjhkMWEwOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjMxZTIwOTI0OGFiMzgxMDEyYjRmY2JjM2MwODI3MDJmOTNjMjgyNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzdiYTY3MTIyY2VkMWZjZjI5N2RmYjBkY2M1NTYyZWVjZjFiOWM0NDU4YjVk
|
10
|
+
MGM4MGI1MWFlYzNhNjg0MzNlYmU0YzYwMzZhMDViNDgwYmVjN2ExZWY3MjJi
|
11
|
+
NGQ0NDRmOThhZjE4MWQwNmEyODk5NmYxNmE0NTkzMmY2YTliMjE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGM2NmNlMmQ2ZGYwZmVhMmEwZWMyYjU1NjJmZTBhYTU1M2UzNzMyMjRlZjRj
|
14
|
+
ZTAzNzM5MDI0MmRlMmU4OWU4MzBlZWUxNTRiMGU4MzE4YWI4YTE3M2M1MGMy
|
15
|
+
ZjI1MWY1YWM5NmQwNWYyYWZhNTk0MTA1OGU4NWVkN2Y4YTUzNDE=
|
@@ -30,7 +30,7 @@ module Hoodoo
|
|
30
30
|
#
|
31
31
|
# ...to create model instances and participate "for free" in whatever
|
32
32
|
# plug-in ActiveRecord modules are mixed into the model classes, such as
|
33
|
-
# Hoodoo::ActiveRecord::Dated.
|
33
|
+
# Hoodoo::ActiveRecord::Dated and Hoodoo::ActiveRecord::ManuallyDated.
|
34
34
|
#
|
35
35
|
# See also:
|
36
36
|
#
|
@@ -117,12 +117,13 @@ module Hoodoo
|
|
117
117
|
|
118
118
|
# TODO: Refactor this to use the scope chain plugin approach in due
|
119
119
|
# course, but for now, pragmatic implementation does the only
|
120
|
-
#
|
120
|
+
# things we currently require - set "created_at"/"updated_at".
|
121
121
|
#
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
122
|
+
unless context.request.dated_from.nil?
|
123
|
+
instance.created_at = instance.updated_at = context.request.dated_from if (
|
124
|
+
( self.include?( Hoodoo::ActiveRecord::Dated ) && self.dating_enabled?() ) ||
|
125
|
+
( self.include?( Hoodoo::ActiveRecord::ManuallyDated ) && self.manual_dating_enabled?() )
|
126
|
+
)
|
126
127
|
end
|
127
128
|
|
128
129
|
return instance
|
@@ -97,14 +97,14 @@ module Hoodoo
|
|
97
97
|
#
|
98
98
|
# == Model instance creation
|
99
99
|
#
|
100
|
-
# It is _VERY_ _IMPORTANT_ that you use
|
101
|
-
# Hoodoo::ActiveRecord::Creator::ClassMethods
|
102
|
-
# resource instances when using
|
100
|
+
# It is _VERY_ _IMPORTANT_ that you use method
|
101
|
+
# Hoodoo::ActiveRecord::Creator::ClassMethods.new_in to create new
|
102
|
+
# resource instances when using dating. You _could_ just manually read the
|
103
103
|
# `context.request.dated_from` value to ensure that an appropriate creation
|
104
104
|
# time is set; presently, `created_at` and `updated_at` are set from the
|
105
105
|
# `dated_from` value. However, using `new_in` for this isolates your code
|
106
106
|
# from any possible under-the-hood implementation changes therein and
|
107
|
-
# future-
|
107
|
+
# future-proofs your code.
|
108
108
|
#
|
109
109
|
module Dated
|
110
110
|
|
@@ -183,7 +183,7 @@ module Hoodoo
|
|
183
183
|
# returns +true+, else +false+.
|
184
184
|
#
|
185
185
|
def dating_enabled?
|
186
|
-
return self.dated_with()
|
186
|
+
return self.dated_with().present?
|
187
187
|
end
|
188
188
|
|
189
189
|
# Return an ActiveRecord::Relation containing the model instances which
|
@@ -109,6 +109,8 @@ module Hoodoo
|
|
109
109
|
# you *MUST* include the ActiveRecord::Relation instances (scopes) inside
|
110
110
|
# any query chain used to read or write data.
|
111
111
|
#
|
112
|
+
# === Show and List
|
113
|
+
#
|
112
114
|
# You might use Hoodoo::ActiveRecord::Finder#list_in or
|
113
115
|
# Hoodoo::ActiveRecord::Finder#acquire_in for +list+ or +show+ actions;
|
114
116
|
# such code changes from e.g.:
|
@@ -119,7 +121,20 @@ module Hoodoo
|
|
119
121
|
#
|
120
122
|
# SomeModel.manually_dated( context ).list_in( context )
|
121
123
|
#
|
122
|
-
#
|
124
|
+
# === Create
|
125
|
+
#
|
126
|
+
# As with automatic dating - see Hoodoo::ActiveRecord::Dated - you should
|
127
|
+
# use method Hoodoo::ActiveRecord::Creator::ClassMethods.new_in to create
|
128
|
+
# new resource instances, to help ensure correct initial date setup and to
|
129
|
+
# help isolate your code from future functionality extensions/changes. An
|
130
|
+
# ActiveRecord +before_create+ filter deals with some of the "behind the
|
131
|
+
# scenes" maintenance but the initial acquisition of dating information
|
132
|
+
# from the prevailing request context only happens for you if you use
|
133
|
+
# Hoodoo::ActiveRecord::Creator::ClassMethods::new_in.
|
134
|
+
#
|
135
|
+
# === Update and Delete
|
136
|
+
#
|
137
|
+
# You *MUST* *NOT* update or delete records using conventional ActiveRecord
|
123
138
|
# methods if you want to use manual dating to record state changes.
|
124
139
|
# Instead, use
|
125
140
|
# Hoodoo::ActiveRecord::ManuallyDated::ClassMethods#manually_dated_update_in
|
@@ -143,6 +158,8 @@ module Hoodoo
|
|
143
158
|
# information on overriding the identifier used to find the target record
|
144
159
|
# and the attribute data used for updates.
|
145
160
|
#
|
161
|
+
# == Rendering
|
162
|
+
#
|
146
163
|
# When rendering, you *MUST* remember to set the resource's +id+ field
|
147
164
|
# from the model's +uuid+ field:
|
148
165
|
#
|
@@ -155,8 +172,20 @@ module Hoodoo
|
|
155
172
|
# }
|
156
173
|
# )
|
157
174
|
#
|
158
|
-
#
|
159
|
-
#
|
175
|
+
# == Associations
|
176
|
+
#
|
177
|
+
# Generally, use of ActiveRecord associations is minimal in most services
|
178
|
+
# because there is an implied database-level coupling of resources and a
|
179
|
+
# temptation to use cross-table ActiveRecord mechanisms for things like
|
180
|
+
# relational UUID integrity checks, rather than inter-resource calls.
|
181
|
+
# Doing so couples resources together at the database rather than keeping
|
182
|
+
# them isolated purely by API, which is often a really bad idea. It is,
|
183
|
+
# however, sometimes necessary for best possible performance, or sometimes
|
184
|
+
# one complex resource may be represented by several models with
|
185
|
+
# relationships between them.
|
186
|
+
#
|
187
|
+
# In such cases, remember to set foreign keys for relational declarations
|
188
|
+
# to a manually dated table via the +uuid+ column - e.g. go from this:
|
160
189
|
#
|
161
190
|
# member.account_id = account.id
|
162
191
|
#
|
@@ -408,10 +437,6 @@ module Hoodoo
|
|
408
437
|
def manual_dating_enabled
|
409
438
|
self.nz_co_loyalty_hoodoo_manually_dated = true
|
410
439
|
|
411
|
-
rounder = Proc.new do | timelike |
|
412
|
-
timelike.to_time.round( SECONDS_DECIMAL_PLACES )
|
413
|
-
end
|
414
|
-
|
415
440
|
# This is the 'tightest'/innermost callback available for creation.
|
416
441
|
# Intentionally have nothing for updates/deletes as the high level
|
417
442
|
# API here must be used; we don't want to introduce any more magic.
|
data/lib/hoodoo/version.rb
CHANGED
@@ -15,6 +15,7 @@ describe Hoodoo::ActiveRecord::Creator do
|
|
15
15
|
class RSpecModelCreatorTest < ActiveRecord::Base
|
16
16
|
include Hoodoo::ActiveRecord::Creator
|
17
17
|
include Hoodoo::ActiveRecord::Dated
|
18
|
+
include Hoodoo::ActiveRecord::ManuallyDated
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
@@ -45,14 +46,57 @@ describe Hoodoo::ActiveRecord::Creator do
|
|
45
46
|
expect( instance.updated_at ).to be_nil
|
46
47
|
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
context 'with "dated_from" given' do
|
50
|
+
before :each do
|
51
|
+
@time = Time.now
|
52
|
+
@context.request.dated_from = @time
|
53
|
+
end
|
51
54
|
|
52
|
-
|
55
|
+
shared_examples 'a dated model' do
|
56
|
+
it 'using the specified dated-from value' do
|
57
|
+
instance = RSpecModelCreatorTest.new_in( @context )
|
58
|
+
|
59
|
+
expect( instance.created_at ).to eq( @time )
|
60
|
+
expect( instance.updated_at ).to eq( @time )
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
shared_examples 'a normal model' do
|
65
|
+
it 'creating with no default timestamps' do
|
66
|
+
instance = RSpecModelCreatorTest.new_in( @context )
|
67
|
+
|
68
|
+
expect( instance.created_at ).to eq( nil )
|
69
|
+
expect( instance.updated_at ).to eq( nil )
|
70
|
+
end
|
71
|
+
end
|
53
72
|
|
54
|
-
|
55
|
-
|
73
|
+
context 'automatic dating present' do
|
74
|
+
context 'and enabled it' do
|
75
|
+
before :each do
|
76
|
+
expect( RSpecModelCreatorTest ).to receive( :dating_enabled? ).once.and_return( true )
|
77
|
+
end
|
78
|
+
|
79
|
+
it_behaves_like 'a dated model'
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'and not enabled it' do
|
83
|
+
it_behaves_like 'a normal model'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'manual dating present' do
|
88
|
+
context 'and enabled it' do
|
89
|
+
before :each do
|
90
|
+
expect( RSpecModelCreatorTest ).to receive( :manual_dating_enabled? ).once.and_return( true )
|
91
|
+
end
|
92
|
+
|
93
|
+
it_behaves_like 'a dated model'
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'and not enabled it' do
|
97
|
+
it_behaves_like 'a normal model'
|
98
|
+
end
|
99
|
+
end
|
56
100
|
end
|
57
101
|
|
58
102
|
it 'creates with provided attributes' do
|
@@ -124,9 +124,15 @@ describe Hoodoo::ActiveRecord::Dated do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
context '#dating_enabled?' do
|
127
|
+
class RSpecNotDated < Hoodoo::ActiveRecord::Base; end
|
128
|
+
|
127
129
|
it 'says it is automatically dated' do
|
128
130
|
expect( model_klass.dating_enabled? ).to eq( true )
|
129
131
|
end
|
132
|
+
|
133
|
+
it 'knows when something is not automatically dated' do
|
134
|
+
expect( RSpecNotDated.dating_enabled? ).to eq( false )
|
135
|
+
end
|
130
136
|
end
|
131
137
|
|
132
138
|
context '#dated_at' do
|
@@ -139,9 +139,15 @@ describe Hoodoo::ActiveRecord::ManuallyDated do
|
|
139
139
|
end
|
140
140
|
|
141
141
|
context '#manual_dating_enabled?' do
|
142
|
+
class RSpecNotManuallyDated < Hoodoo::ActiveRecord::Base; end
|
143
|
+
|
142
144
|
it 'says it is manually dated' do
|
143
145
|
expect( RSpecModelManualDateTest.manual_dating_enabled? ).to eq( true )
|
144
146
|
end
|
147
|
+
|
148
|
+
it 'knows when something is not automatically dated' do
|
149
|
+
expect( RSpecNotManuallyDated.manual_dating_enabled? ).to eq( false )
|
150
|
+
end
|
145
151
|
end
|
146
152
|
|
147
153
|
context '#manually_dated_at' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoodoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Loyalty New Zealand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kgio
|