sprig 0.1.5 → 0.1.6
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/lib/sprig/seed/attribute.rb +44 -15
- data/lib/sprig/version.rb +1 -1
- data/spec/db/activerecord.db +0 -0
- data/spec/fixtures/models/post.rb +2 -0
- data/spec/fixtures/models/tag.rb +3 -0
- data/spec/fixtures/seeds/test/posts_with_habtm.yml +7 -0
- data/spec/fixtures/seeds/test/tags.yml +5 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/sprig_spec.rb +18 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a11f717b26ca547b63e3a10d77e90e5fb0b34f99
|
4
|
+
data.tar.gz: 875a60cf93f12dda5e3cf04f17dca18c1201f53c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c5b80e9fbc98aeca33b2f535336a4ac577f4837ecc88b5315351f5cef5582bf67b6fad52a4af4b706c045bdb3120461c1c74b5e118eb177406f66a824e5cf99
|
7
|
+
data.tar.gz: 7660d42b5f0ca71849c63de2abaef6cc4ad324ee08598b00676b4196c80050eeb49264589258e601504ad5bac97514edfe42d5ec0624dbdb87193a903d0db875
|
data/lib/sprig/seed/attribute.rb
CHANGED
@@ -9,46 +9,75 @@ module Sprig
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def dependencies
|
12
|
-
@dependencies ||=
|
12
|
+
@dependencies ||= find_dependencies_within(raw_value).uniq
|
13
13
|
end
|
14
14
|
|
15
15
|
def value
|
16
|
-
compute_value if @value.nil?
|
16
|
+
@value = compute_value(raw_value) if @value.nil?
|
17
17
|
|
18
18
|
@value
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
-
def
|
24
|
-
if
|
25
|
-
|
26
|
-
|
23
|
+
def find_dependencies_within(value)
|
24
|
+
if array?(value)
|
25
|
+
find_dependencies_within_array(value)
|
26
|
+
elsif string?(value) && computed_value?(value)
|
27
|
+
find_dependencies_within_string(value)
|
27
28
|
else
|
28
29
|
[]
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
def
|
33
|
-
|
33
|
+
def find_dependencies_within_array(array)
|
34
|
+
array.flat_map do |value|
|
35
|
+
find_dependencies_within(value)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def find_dependencies_within_string(string)
|
40
|
+
matches = string.scan(/(sprig_record\(([A-Z][^,]*), ([\d]*)\))+/)
|
41
|
+
matches.map { |match| Dependency.for(match[1], match[2]) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def string?(value)
|
45
|
+
value.is_a?(String)
|
46
|
+
end
|
47
|
+
|
48
|
+
def array?(value)
|
49
|
+
value.is_a?(Array)
|
34
50
|
end
|
35
51
|
|
36
|
-
def computed_value?
|
37
|
-
|
52
|
+
def computed_value?(value)
|
53
|
+
String(value) =~ computed_value_regex
|
38
54
|
end
|
39
55
|
|
40
56
|
def computed_value_regex
|
41
57
|
/<%[=]?(.*)%>/
|
42
58
|
end
|
43
59
|
|
44
|
-
def compute_value
|
45
|
-
|
46
|
-
|
47
|
-
|
60
|
+
def compute_value(value)
|
61
|
+
if array?(value)
|
62
|
+
compute_array_value(value)
|
63
|
+
elsif string?(value) && computed_value?(value)
|
64
|
+
compute_string_value(value)
|
48
65
|
else
|
49
|
-
|
66
|
+
value
|
50
67
|
end
|
51
68
|
end
|
69
|
+
|
70
|
+
def compute_array_value(array)
|
71
|
+
array.map do |value|
|
72
|
+
compute_value(value)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def compute_string_value(string)
|
77
|
+
matches = computed_value_regex.match(string)
|
78
|
+
eval(matches[1])
|
79
|
+
end
|
80
|
+
|
52
81
|
end
|
53
82
|
end
|
54
83
|
end
|
data/lib/sprig/version.rb
CHANGED
data/spec/db/activerecord.db
CHANGED
Binary file
|
data/spec/spec_helper.rb
CHANGED
@@ -58,6 +58,12 @@ Post.connection.execute "CREATE TABLE posts (id INTEGER PRIMARY KEY AUTOINCREMEN
|
|
58
58
|
Comment.connection.execute "DROP TABLE IF EXISTS comments;"
|
59
59
|
Comment.connection.execute "CREATE TABLE comments (id INTEGER PRIMARY KEY , post_id INTEGER, body VARCHAR(255));"
|
60
60
|
|
61
|
+
Tag.connection.execute "DROP TABLE IF EXISTS tags;"
|
62
|
+
Tag.connection.execute "CREATE TABLE tags (id INTEGER PRIMARY KEY , name VARCHAR(255));"
|
63
|
+
|
64
|
+
Tag.connection.execute "DROP TABLE IF EXISTS posts_tags;"
|
65
|
+
Tag.connection.execute "CREATE TABLE posts_tags (id INTEGER PRIMARY KEY , post_id INTEGER, tag_id INTEGER);"
|
66
|
+
|
61
67
|
# Helpers
|
62
68
|
#
|
63
69
|
# Setup fake `Rails.root`
|
data/spec/sprig_spec.rb
CHANGED
@@ -235,6 +235,24 @@ describe "Seeding an application" do
|
|
235
235
|
end
|
236
236
|
end
|
237
237
|
|
238
|
+
context "with has_and_belongs_to_many relationships" do
|
239
|
+
around do |example|
|
240
|
+
load_seeds('posts_with_habtm.yml', 'tags.yml', &example)
|
241
|
+
end
|
242
|
+
|
243
|
+
it "saves the habtm relationships" do
|
244
|
+
sprig [
|
245
|
+
Tag,
|
246
|
+
{
|
247
|
+
:class => Post,
|
248
|
+
:source => open('spec/fixtures/seeds/test/posts_with_habtm.yml')
|
249
|
+
}
|
250
|
+
]
|
251
|
+
|
252
|
+
Post.first.tags.map(&:name).should == ['Botany', 'Biology']
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
238
256
|
context "with cyclic dependencies" do
|
239
257
|
around do |example|
|
240
258
|
load_seeds('comments.yml', 'posts_with_cyclic_dependencies.yml', &example)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lawson Kurtz
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-06-
|
12
|
+
date: 2014-06-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -201,6 +201,7 @@ files:
|
|
201
201
|
- spec/fixtures/config/environments/test.rb
|
202
202
|
- spec/fixtures/models/comment.rb
|
203
203
|
- spec/fixtures/models/post.rb
|
204
|
+
- spec/fixtures/models/tag.rb
|
204
205
|
- spec/fixtures/models/user.rb
|
205
206
|
- spec/fixtures/seeds/staging/posts.yml
|
206
207
|
- spec/fixtures/seeds/test/comments.yml
|
@@ -219,6 +220,8 @@ files:
|
|
219
220
|
- spec/fixtures/seeds/test/posts_missing_record.yml
|
220
221
|
- spec/fixtures/seeds/test/posts_with_cyclic_dependencies.yml
|
221
222
|
- spec/fixtures/seeds/test/posts_with_files.yml
|
223
|
+
- spec/fixtures/seeds/test/posts_with_habtm.yml
|
224
|
+
- spec/fixtures/seeds/test/tags.yml
|
222
225
|
- spec/lib/generators/sprig/install_generator_spec.rb
|
223
226
|
- spec/lib/sprig/configuration_spec.rb
|
224
227
|
- spec/lib/sprig/directive_list_spec.rb
|
@@ -268,6 +271,7 @@ test_files:
|
|
268
271
|
- spec/fixtures/config/environments/test.rb
|
269
272
|
- spec/fixtures/models/comment.rb
|
270
273
|
- spec/fixtures/models/post.rb
|
274
|
+
- spec/fixtures/models/tag.rb
|
271
275
|
- spec/fixtures/models/user.rb
|
272
276
|
- spec/fixtures/seeds/staging/posts.yml
|
273
277
|
- spec/fixtures/seeds/test/comments.yml
|
@@ -286,6 +290,8 @@ test_files:
|
|
286
290
|
- spec/fixtures/seeds/test/posts_missing_record.yml
|
287
291
|
- spec/fixtures/seeds/test/posts_with_cyclic_dependencies.yml
|
288
292
|
- spec/fixtures/seeds/test/posts_with_files.yml
|
293
|
+
- spec/fixtures/seeds/test/posts_with_habtm.yml
|
294
|
+
- spec/fixtures/seeds/test/tags.yml
|
289
295
|
- spec/lib/generators/sprig/install_generator_spec.rb
|
290
296
|
- spec/lib/sprig/configuration_spec.rb
|
291
297
|
- spec/lib/sprig/directive_list_spec.rb
|