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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a2500ec348b79679f29e89f4109b33ee91f11fd
4
- data.tar.gz: c6248310b5089e1d03778caeb1d7e09a9e7d4c74
3
+ metadata.gz: d8c76050cd88f10b7aa5734b205c1bdc5afbc5ea
4
+ data.tar.gz: ffeebeb96d52c7fa0cd0ba39c9c0fdf0d337c247
5
5
  SHA512:
6
- metadata.gz: d95948af8e4146673d3152e4e8e0a9de1e554641d86d404998dd2c794fc8aeb7f8cd73af9f68eabf115459e0cca08ebcaa5245dd461ac98f00e2010b9ef56822
7
- data.tar.gz: f63975d16165e30e95fa7e72a5ee3fa0ab68c6e69b7b4d56507d49ee6f5ea3454de4bc8c5d480b5598e713e75f689c5f4b4d4f5737170e0f3effab6a360f84f0
6
+ metadata.gz: a35c299bee763d65c441323002da0b3f74405a2ecd9a831bfa5e108c033b3a3c129f151649e878293ea3f27d060265030054ec65ee0e252411fb86cffb3a6bb7
7
+ data.tar.gz: 99024ba29c6b31096a3a18332b31e1ba1594d062009cdba4731c592d39edc64b5bb4a1ceeff2632dbb2fd3bdf9d28b1adc9dc14912073b696cb5c89961a22a4d
@@ -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 = computed_value_regex.match(string)
78
- eval(matches[1])
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
@@ -1,3 +1,3 @@
1
1
  module Sprig
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
3
3
  end
Binary file
@@ -0,0 +1,4 @@
1
+ records:
2
+ - sprig_id: 1
3
+ title: '<%= "Partially" %> <%= "Dynamic" %> Title'
4
+ content: 'Yaml content'
@@ -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.1.9
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-10-12 00:00:00.000000000 Z
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