config_scripts 0.4.6 → 0.4.7
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/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/config_scripts/seeds/seed_type.rb +11 -0
- data/lib/config_scripts/version.rb +1 -1
- data/spec/seeds/seed_type_spec.rb +37 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8befb2a6a90a42c725317ff2cce3aee47194c9a
|
4
|
+
data.tar.gz: 2eb29a5f3a001b812da7d78bd0ad581263d29c67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c311188336d1d8dd04d3664203adf1247ecda54d31ac901e711d410c3ec6cc6cca71937dd61fbb5e4c304e2b117eb0a5704ee9e1932f15400507256f25fff09
|
7
|
+
data.tar.gz: 4a3dcbbc6ea5c60a60e1586d45b43d33afc651e890282feae05c66ccd0fc3677b5acda00f90072203bddb5648b65c079afc2d91d5d4aced29c70e9664ba1d19d
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -23,8 +23,8 @@ Generate the new migrations for the config_scripts table:
|
|
23
23
|
|
24
24
|
And run them:
|
25
25
|
|
26
|
-
$ rake
|
26
|
+
$ rake config_scripts:run_pending
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
|
-
See [the wiki](https://github.com/brownleej/config-scripts-gem/wiki) for usage examples.
|
30
|
+
See [the wiki](https://github.com/brownleej/config-scripts-gem/wiki) for usage examples.
|
@@ -43,6 +43,10 @@ module ConfigScripts
|
|
43
43
|
# seed file.
|
44
44
|
attr_reader :dynamic_writers
|
45
45
|
|
46
|
+
# @return [Proc]
|
47
|
+
# The block that will be run when fetching items.
|
48
|
+
attr_reader :dynamic_fetcher
|
49
|
+
|
46
50
|
# @return [Array<Array>]
|
47
51
|
# The scopes that we apply when fetching items.
|
48
52
|
#
|
@@ -153,6 +157,12 @@ module ConfigScripts
|
|
153
157
|
@dynamic_writers[attribute] = block
|
154
158
|
end
|
155
159
|
|
160
|
+
# This method registers a custom block that will be run when fetching
|
161
|
+
# records.
|
162
|
+
def when_fetching(&block)
|
163
|
+
@dynamic_fetcher = block
|
164
|
+
end
|
165
|
+
|
156
166
|
# @!group Reading and Writing
|
157
167
|
|
158
168
|
# This method writes the seed data file to a folder.
|
@@ -318,6 +328,7 @@ module ConfigScripts
|
|
318
328
|
#
|
319
329
|
# @return [Relation]
|
320
330
|
def items
|
331
|
+
return @dynamic_fetcher.call if @dynamic_fetcher
|
321
332
|
records = self.all
|
322
333
|
self.scopes.each { |method, args| records = records.send(method, *args) }
|
323
334
|
records
|
@@ -373,24 +373,47 @@ describe ConfigScripts::Seeds::SeedType do
|
|
373
373
|
|
374
374
|
subject { seed_type.items }
|
375
375
|
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
376
|
+
context "with scopes" do
|
377
|
+
before do
|
378
|
+
seed_type.has_scope :where, 'name like ?', 'John%'
|
379
|
+
seed_type.has_scope :order, 'name ASC'
|
380
|
+
end
|
380
381
|
|
381
|
-
|
382
|
-
|
383
|
-
|
382
|
+
it "gets the records by applying the scope" do
|
383
|
+
expect(subject).to eq [person2, person1]
|
384
|
+
end
|
385
|
+
|
386
|
+
it "does not include a record filtered out by a default scope" do
|
387
|
+
person2.update_attributes archived: true
|
388
|
+
expect(subject).not_to include person2
|
389
|
+
end
|
384
390
|
|
385
|
-
|
386
|
-
|
387
|
-
|
391
|
+
it "allows using the unscoped method to filter out records by a scope" do
|
392
|
+
seed_type.has_scope :unscoped
|
393
|
+
person2.update_attributes archived: true
|
394
|
+
expect(subject).to include person2
|
395
|
+
end
|
388
396
|
end
|
389
397
|
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
398
|
+
context "with a custom fetcher" do
|
399
|
+
before do
|
400
|
+
seed_type.when_fetching do
|
401
|
+
person2.update_attributes name: 'James Smith'
|
402
|
+
person3.update_attributes name: 'Jane Williams'
|
403
|
+
people = Person.where('name LIKE ?', 'John%')
|
404
|
+
people += Person.where('name LIKE ?', 'Jane%')
|
405
|
+
people
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
it "gets the records that are included in the fetcher" do
|
410
|
+
expect(subject).to include person1
|
411
|
+
expect(subject).to include person3
|
412
|
+
end
|
413
|
+
|
414
|
+
it "does not get records that are excluded by the fetcher" do
|
415
|
+
expect(subject).not_to include person2
|
416
|
+
end
|
394
417
|
end
|
395
418
|
end
|
396
419
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: config_scripts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Brownlee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|