application_seeds 0.8.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +12 -0
- data/README.md +12 -8
- data/lib/application_seeds/attributes.rb +8 -13
- data/lib/application_seeds/version.rb +1 -1
- data/spec/application_seeds_spec.rb +6 -6
- data/spec/attributes_spec.rb +18 -6
- metadata +15 -31
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 51edace901b6a6cbdfd20458e6dc99d35c9a2572
|
4
|
+
data.tar.gz: b98b2065d636b5244c8fc2ef560edbb088ea9d7a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e8250b7a647ba433c8f71bda00c048664e367c627562df997c846903650cb31d02a972963d7452b657ea74bd38b4f752e1760133a1b6d8ae862de7c852e5abfb
|
7
|
+
data.tar.gz: ad559e086a4a4e9d79cec9cd7a14ddedb5c1d6b5cca7165e7f37716b413e71eef967a62866ff31b2a63ca2a5fe762f616df2e2dff39f72e468e6954d655e57cb
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -459,7 +459,7 @@ does not.
|
|
459
459
|
ApplicationSeeds.campaigns # where "campaigns" is the name of the seed file
|
460
460
|
```
|
461
461
|
|
462
|
-
This call returns a hash with one or more entries (depending on the
|
462
|
+
This call returns a hash with one or more entries (depending on the contents of the seed file).
|
463
463
|
The IDs of the object are the keys, and a hash containing the object's attributes are the values.
|
464
464
|
An exception is raised if no seed data could be with the given name.
|
465
465
|
|
@@ -490,14 +490,19 @@ seed data could be found with the given ID.
|
|
490
490
|
ApplicationSeeds.campaigns(foo: 'bar', name: 'John') # where "campaigns" is the name of the seed file
|
491
491
|
```
|
492
492
|
|
493
|
-
This call returns the seed data that contains the specified attributes,
|
494
|
-
and the specified attribute values. It returns a hash with zero or more
|
495
|
-
entries. The IDs of the object are the keys of the hash, and a hash
|
496
|
-
containing the object's attributes are the values. Any empty hash will
|
497
|
-
be returned if no seed data could be found with the given attribute names
|
498
|
-
and values.
|
493
|
+
This call returns the seed data that contains the specified attributes, and the specified attribute values. It returns a hash with zero or more entries. The IDs of the object are the keys of the hash, and a hash containing the object's attributes are the values. Any empty hash will be returned if no seed data could be found with the given attribute names and values.
|
499
494
|
|
500
495
|
|
496
|
+
### Accessing attributes
|
497
|
+
|
498
|
+
A seed datum is a hash of attributes (with indifferent access):
|
499
|
+
|
500
|
+
```ruby
|
501
|
+
campaign = ApplicationSeeds.campaigns(642)
|
502
|
+
campaign["description"] # => "Best pizza in Chicago"
|
503
|
+
campaign[:budget] # => 10000
|
504
|
+
```
|
505
|
+
|
501
506
|
### Creating an object
|
502
507
|
|
503
508
|
```ruby
|
@@ -507,7 +512,6 @@ ApplicationSeeds.create_object!(Campaign, id, attributes)
|
|
507
512
|
This call will create a new instance of the `Campaign` class, with the
|
508
513
|
specified id and attributes.
|
509
514
|
|
510
|
-
|
511
515
|
### Rejecting specific attributes
|
512
516
|
|
513
517
|
```ruby
|
@@ -1,32 +1,27 @@
|
|
1
1
|
require 'delegate'
|
2
2
|
|
3
3
|
module ApplicationSeeds
|
4
|
-
class Attributes < DelegateClass(
|
4
|
+
class Attributes < DelegateClass(ActiveSupport::HashWithIndifferentAccess)
|
5
5
|
|
6
6
|
def initialize(attributes)
|
7
|
-
super(attributes)
|
7
|
+
super(attributes.with_indifferent_access)
|
8
8
|
end
|
9
9
|
|
10
10
|
def select_attributes(*attribute_names)
|
11
11
|
attribute_names.map!(&:to_s)
|
12
|
-
Attributes.new(select { |k,v| attribute_names.include?(k) })
|
12
|
+
Attributes.new(select { |k, v| attribute_names.include?(k) })
|
13
13
|
end
|
14
14
|
|
15
15
|
def reject_attributes(*attribute_names)
|
16
16
|
attribute_names.map!(&:to_s)
|
17
|
-
Attributes.new(reject { |k,v| attribute_names.include?(k) })
|
17
|
+
Attributes.new(reject { |k, v| attribute_names.include?(k) })
|
18
18
|
end
|
19
19
|
|
20
20
|
def map_attributes(mapping)
|
21
|
-
mapping.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
if mapping.keys.include?(k)
|
26
|
-
mapped[mapping[k].to_s] = v
|
27
|
-
else
|
28
|
-
mapped[k] = v
|
29
|
-
end
|
21
|
+
mapping = mapping.with_indifferent_access
|
22
|
+
mapped = inject({}) do |hash, (k, v)|
|
23
|
+
mapped_key = mapping.fetch(k) { k }
|
24
|
+
hash.merge!(mapped_key => v)
|
30
25
|
end
|
31
26
|
Attributes.new(mapped)
|
32
27
|
end
|
@@ -84,7 +84,7 @@ describe "ApplicationSeeds" do
|
|
84
84
|
|
85
85
|
context "with a valid dataset" do
|
86
86
|
before do
|
87
|
-
ApplicationSeeds.
|
87
|
+
allow(ApplicationSeeds).to receive(:store_dataset)
|
88
88
|
ApplicationSeeds.dataset = "test_data_set"
|
89
89
|
end
|
90
90
|
|
@@ -244,7 +244,7 @@ describe "ApplicationSeeds" do
|
|
244
244
|
|
245
245
|
describe "with a nested dataset" do
|
246
246
|
before do
|
247
|
-
ApplicationSeeds.
|
247
|
+
allow(ApplicationSeeds).to receive(:store_dataset)
|
248
248
|
ApplicationSeeds.dataset = "level_3"
|
249
249
|
end
|
250
250
|
|
@@ -281,7 +281,7 @@ describe "ApplicationSeeds" do
|
|
281
281
|
person = ApplicationSeeds.people(:sam_jones)
|
282
282
|
expect(person['first_name']).to eql("Sam")
|
283
283
|
end
|
284
|
-
it "gives the data in lower levels
|
284
|
+
it "gives the data in lower levels precedence" do
|
285
285
|
person = ApplicationSeeds.people(:ken_adams)
|
286
286
|
expect(person['first_name']).to eql("Ken")
|
287
287
|
end
|
@@ -292,7 +292,7 @@ describe "ApplicationSeeds" do
|
|
292
292
|
expect(ApplicationSeeds.config_value(:num_companies)).to eql(5)
|
293
293
|
expect(ApplicationSeeds.config_value(:num_departments)).to eql(3)
|
294
294
|
end
|
295
|
-
it "gives the data in lower levels
|
295
|
+
it "gives the data in lower levels precedence" do
|
296
296
|
expect(ApplicationSeeds.config_value(:num_people)).to eql(10)
|
297
297
|
end
|
298
298
|
end
|
@@ -301,7 +301,7 @@ describe "ApplicationSeeds" do
|
|
301
301
|
describe "with UUIDs configured for all seed types" do
|
302
302
|
before do
|
303
303
|
ApplicationSeeds.instance_variable_set("@dataset", nil)
|
304
|
-
ApplicationSeeds.
|
304
|
+
allow(ApplicationSeeds).to receive(:store_dataset)
|
305
305
|
ApplicationSeeds.config = { :id_type => :uuid }
|
306
306
|
ApplicationSeeds.dataset = "test_data_set"
|
307
307
|
end
|
@@ -329,7 +329,7 @@ describe "ApplicationSeeds" do
|
|
329
329
|
describe "with data type specific key types configured" do
|
330
330
|
before do
|
331
331
|
ApplicationSeeds.instance_variable_set("@dataset", nil)
|
332
|
-
ApplicationSeeds.
|
332
|
+
allow(ApplicationSeeds).to receive(:store_dataset)
|
333
333
|
ApplicationSeeds.config = { :id_type => :uuid, :companies_id_type => :integer }
|
334
334
|
ApplicationSeeds.dataset = "test_data_set"
|
335
335
|
end
|
data/spec/attributes_spec.rb
CHANGED
@@ -4,12 +4,24 @@ describe "Attributes" do
|
|
4
4
|
before do
|
5
5
|
@attributes = ApplicationSeeds::Attributes.new("first_name" => "Billy",
|
6
6
|
"last_name" => "Bob",
|
7
|
-
"occupation" => "Bus Driver"
|
7
|
+
"occupation" => "Bus Driver",
|
8
|
+
major_house: "Atreides")
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "attribute access" do
|
12
|
+
it "works with a string key" do
|
13
|
+
expect(@attributes["first_name"]).to eq("Billy")
|
14
|
+
expect(@attributes["major_house"]).to eq("Atreides")
|
15
|
+
end
|
16
|
+
it "works with a symbol key" do
|
17
|
+
expect(@attributes[:first_name]).to eq("Billy")
|
18
|
+
expect(@attributes[:major_house]).to eq("Atreides")
|
19
|
+
end
|
8
20
|
end
|
9
21
|
|
10
22
|
describe "#select_attributes" do
|
11
23
|
before do
|
12
|
-
@selected_attributes = @attributes.select_attributes(:first_name,
|
24
|
+
@selected_attributes = @attributes.select_attributes(:first_name, "occupation")
|
13
25
|
end
|
14
26
|
it "returns only the select attributes" do
|
15
27
|
expect(@selected_attributes).to eql({ "first_name" => "Billy", "occupation" => "Bus Driver" })
|
@@ -21,7 +33,7 @@ describe "Attributes" do
|
|
21
33
|
|
22
34
|
describe "#reject_attributes" do
|
23
35
|
before do
|
24
|
-
@rejected_attributes = @attributes.reject_attributes(:first_name, :last_name)
|
36
|
+
@rejected_attributes = @attributes.reject_attributes(:first_name, :last_name, "major_house")
|
25
37
|
end
|
26
38
|
it "returns only the select attributes" do
|
27
39
|
expect(@rejected_attributes).to eql({ "occupation" => "Bus Driver" })
|
@@ -33,10 +45,10 @@ describe "Attributes" do
|
|
33
45
|
|
34
46
|
describe "#map_attributes" do
|
35
47
|
before do
|
36
|
-
@mapped_attributes = @attributes.map_attributes(:first_name => :fname,
|
48
|
+
@mapped_attributes = @attributes.map_attributes(:first_name => :fname, 'last_name' => 'lname')
|
37
49
|
end
|
38
|
-
it "
|
39
|
-
expect(@mapped_attributes).to eql({ "fname" => "Billy", "lname" => "Bob", "occupation" => "Bus Driver" })
|
50
|
+
it "uses the new keys" do
|
51
|
+
expect(@mapped_attributes).to eql({ "fname" => "Billy", "lname" => "Bob", "occupation" => "Bus Driver", "major_house" => "Atreides" })
|
40
52
|
end
|
41
53
|
it "returns a new instance of the Attributes class" do
|
42
54
|
expect(@mapped_attributes).to be_a(ApplicationSeeds::Attributes)
|
metadata
CHANGED
@@ -1,78 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: application_seeds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.9.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- John Wood
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-20 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activesupport
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: pg
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rake
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
description: A library for managing standardized application seed data
|
@@ -111,33 +102,26 @@ files:
|
|
111
102
|
homepage: https://github.com/centro/application_seeds
|
112
103
|
licenses:
|
113
104
|
- MIT
|
105
|
+
metadata: {}
|
114
106
|
post_install_message:
|
115
107
|
rdoc_options: []
|
116
108
|
require_paths:
|
117
109
|
- lib
|
118
110
|
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
-
none: false
|
120
111
|
requirements:
|
121
|
-
- -
|
112
|
+
- - '>='
|
122
113
|
- !ruby/object:Gem::Version
|
123
114
|
version: '0'
|
124
|
-
segments:
|
125
|
-
- 0
|
126
|
-
hash: -4366839030827640870
|
127
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
-
none: false
|
129
116
|
requirements:
|
130
|
-
- -
|
117
|
+
- - '>='
|
131
118
|
- !ruby/object:Gem::Version
|
132
119
|
version: '0'
|
133
|
-
segments:
|
134
|
-
- 0
|
135
|
-
hash: -4366839030827640870
|
136
120
|
requirements: []
|
137
121
|
rubyforge_project:
|
138
|
-
rubygems_version:
|
122
|
+
rubygems_version: 2.0.14
|
139
123
|
signing_key:
|
140
|
-
specification_version:
|
124
|
+
specification_version: 4
|
141
125
|
summary: A library for managing a standardized set of seed data for applications in
|
142
126
|
a non-production environment
|
143
127
|
test_files:
|