config_scripts 0.4.6 → 0.4.7

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
  SHA1:
3
- metadata.gz: 47e36d187f881d51081e4264d4b744b4349cbd1e
4
- data.tar.gz: b7758b32f51e15b1f5b70c779714113e48e513a7
3
+ metadata.gz: a8befb2a6a90a42c725317ff2cce3aee47194c9a
4
+ data.tar.gz: 2eb29a5f3a001b812da7d78bd0ad581263d29c67
5
5
  SHA512:
6
- metadata.gz: 91db88c121aff5140b627770f806068c9e90f73b6e26d5d545fabedcb94287258df64e05fca3143648591b80b23e538f6503fe0d74e2bfacfe2cbd7152ce6e34
7
- data.tar.gz: 50a9fda8901d06c93eaf42a1134244c55c2dd09dc8b28d5f6927ba78ad6ca48d2d97594ee4556649a0384609199124243357440a607d88420cbaf9f5f9af2db7
6
+ metadata.gz: 6c311188336d1d8dd04d3664203adf1247ecda54d31ac901e711d410c3ec6cc6cca71937dd61fbb5e4c304e2b117eb0a5704ee9e1932f15400507256f25fff09
7
+ data.tar.gz: 4a3dcbbc6ea5c60a60e1586d45b43d33afc651e890282feae05c66ccd0fc3677b5acda00f90072203bddb5648b65c079afc2d91d5d4aced29c70e9664ba1d19d
@@ -1,3 +1,6 @@
1
+ # Verson 0.4.7 - 11 December 2014
2
+ * Allows seed types to provide their own implementation for fetching items.
3
+
1
4
  # Version 0.4.6 - 28 October 2014
2
5
  * Serializes boolean values as 1 and 0 to make sure they get fetched properly
3
6
  when used in identifiers
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- config_scripts (0.4.5)
4
+ config_scripts (0.4.6)
5
5
  rails (> 3.0.0)
6
6
 
7
7
  GEM
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 db:migrate
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
@@ -1,4 +1,4 @@
1
1
  module ConfigScripts
2
2
  # The current version of the library.
3
- VERSION = "0.4.6"
3
+ VERSION = "0.4.7"
4
4
  end
@@ -373,24 +373,47 @@ describe ConfigScripts::Seeds::SeedType do
373
373
 
374
374
  subject { seed_type.items }
375
375
 
376
- before do
377
- seed_type.has_scope :where, 'name like ?', 'John%'
378
- seed_type.has_scope :order, 'name ASC'
379
- end
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
- it "gets the records by applying the scope" do
382
- expect(subject).to eq [person2, person1]
383
- end
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
- it "does not include a record filtered out by a default scope" do
386
- person2.update_attributes archived: true
387
- expect(subject).not_to include person2
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
- it "allows using the unscoped method to filter out records by a scope" do
391
- seed_type.has_scope :unscoped
392
- person2.update_attributes archived: true
393
- expect(subject).to include person2
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.6
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-10-29 00:00:00.000000000 Z
11
+ date: 2014-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails