sprig 0.1.9 → 0.2.0
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 +27 -3
- data/lib/sprig/version.rb +1 -1
- data/spec/db/activerecord.db +0 -0
- data/spec/fixtures/seeds/test/posts_partially_dynamic_value.yml +4 -0
- data/spec/sprig_spec.rb +18 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8c76050cd88f10b7aa5734b205c1bdc5afbc5ea
|
4
|
+
data.tar.gz: ffeebeb96d52c7fa0cd0ba39c9c0fdf0d337c247
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a35c299bee763d65c441323002da0b3f74405a2ecd9a831bfa5e108c033b3a3c129f151649e878293ea3f27d060265030054ec65ee0e252411fb86cffb3a6bb7
|
7
|
+
data.tar.gz: 99024ba29c6b31096a3a18332b31e1ba1594d062009cdba4731c592d39edc64b5bb4a1ceeff2632dbb2fd3bdf9d28b1adc9dc14912073b696cb5c89961a22a4d
|
data/lib/sprig/seed/attribute.rb
CHANGED
@@ -54,7 +54,7 @@ module Sprig
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def computed_value_regex
|
57
|
-
|
57
|
+
/(<%=?(.*?)%>)/
|
58
58
|
end
|
59
59
|
|
60
60
|
def compute_value(value)
|
@@ -73,9 +73,33 @@ module Sprig
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
def completely_dynamic_value?(string, matches)
|
77
|
+
return false if matches.count > 1
|
78
|
+
|
79
|
+
test_string = string.clone
|
80
|
+
|
81
|
+
matches.each do |match|
|
82
|
+
test_string = test_string.sub(match[0], "")
|
83
|
+
end
|
84
|
+
|
85
|
+
test_string.strip.length == 0
|
86
|
+
end
|
87
|
+
|
76
88
|
def compute_string_value(string)
|
77
|
-
matches =
|
78
|
-
|
89
|
+
matches = string.scan(computed_value_regex)
|
90
|
+
|
91
|
+
if completely_dynamic_value?(string, matches)
|
92
|
+
# If the dynamic portion is the entire value, return the result of the eval
|
93
|
+
# (This allows for the return of non-string types.)
|
94
|
+
eval(matches.first[1])
|
95
|
+
else
|
96
|
+
# Otherwise return the dynamic portion within the larger string.
|
97
|
+
string.clone.tap do |return_string|
|
98
|
+
matches.each do |match|
|
99
|
+
return_string.sub!(match[0], eval(match[1]))
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
79
103
|
end
|
80
104
|
|
81
105
|
end
|
data/lib/sprig/version.rb
CHANGED
data/spec/db/activerecord.db
CHANGED
Binary file
|
data/spec/sprig_spec.rb
CHANGED
@@ -53,6 +53,24 @@ describe "Seeding an application" do
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
context "with a partially-dynamic value" do
|
57
|
+
around do |example|
|
58
|
+
load_seeds('posts_partially_dynamic_value.yml', &example)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "seeds the db with the full value" do
|
62
|
+
sprig [
|
63
|
+
{
|
64
|
+
:class => Post,
|
65
|
+
:source => open('spec/fixtures/seeds/test/posts_partially_dynamic_value.yml')
|
66
|
+
}
|
67
|
+
]
|
68
|
+
|
69
|
+
Post.count.should == 1
|
70
|
+
Post.pluck(:title).should =~ ['Partially Dynamic Title']
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
56
74
|
context "with a symlinked file" do
|
57
75
|
let(:env) { Rails.env }
|
58
76
|
|
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.
|
4
|
+
version: 0.2.0
|
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: 2015-
|
12
|
+
date: 2015-11-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: appraisal
|
@@ -259,6 +259,7 @@ files:
|
|
259
259
|
- spec/fixtures/seeds/test/posts_find_existing_by_single.yml
|
260
260
|
- spec/fixtures/seeds/test/posts_missing_dependency.yml
|
261
261
|
- spec/fixtures/seeds/test/posts_missing_record.yml
|
262
|
+
- spec/fixtures/seeds/test/posts_partially_dynamic_value.yml
|
262
263
|
- spec/fixtures/seeds/test/posts_with_cyclic_dependencies.yml
|
263
264
|
- spec/fixtures/seeds/test/posts_with_files.yml
|
264
265
|
- spec/fixtures/seeds/test/posts_with_habtm.yml
|
@@ -336,6 +337,7 @@ test_files:
|
|
336
337
|
- spec/fixtures/seeds/test/posts_find_existing_by_single.yml
|
337
338
|
- spec/fixtures/seeds/test/posts_missing_dependency.yml
|
338
339
|
- spec/fixtures/seeds/test/posts_missing_record.yml
|
340
|
+
- spec/fixtures/seeds/test/posts_partially_dynamic_value.yml
|
339
341
|
- spec/fixtures/seeds/test/posts_with_cyclic_dependencies.yml
|
340
342
|
- spec/fixtures/seeds/test/posts_with_files.yml
|
341
343
|
- spec/fixtures/seeds/test/posts_with_habtm.yml
|