data_magic 0.15.1 → 0.15.2

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: 814ee84605ee66b5e5c6e7493b4bc864ab34e10f
4
- data.tar.gz: e6bee36e63b02f533322589074d22364e46eadba
3
+ metadata.gz: 5c7bbf3adc899115c9e7a9adf920fad08da35db0
4
+ data.tar.gz: 27b97a2d7acffc7b80ed7aec7bd28b6e7e3d22de
5
5
  SHA512:
6
- metadata.gz: fb07d62d46cb5ffb3d3c9d33dc92b828d97e1b63e9e7f28a743497ce872a0f17f474ee65369436cd86d9d9226346a443425c213b4d0c14f75dce43811d2ffec3
7
- data.tar.gz: f3f01cebb23addec27bb047028b0d9c40dcde188464d75b7e667b580881dbac15c8cf704d078cb15b53fd4bb949f118cf13c122544baccf018870d4b03924a7d
6
+ metadata.gz: ef9a452bfdcb01ffb56ac7b45e4a75bbcff617ac00ed3a4baf9cf8383d138e70e8c325ea1daea970951cf207a4d9e8e1896e77893f70a7c8d7bac3423edb2cc2
7
+ data.tar.gz: 8fea34907191332335c7c6a49201140bcd937bdd1b9a46bce24fe3e93f7ea46c5a928cdb09bc58bc094ee48dc121c73353cb88f485cd5fdd720ebbb38247a447
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ === Version 0.15.2 / 2013-7-17
2
+ * Fixes
3
+ * Display better message when key is not found (Thanks Guillaume Malette)
4
+ * Properly handling numeric values (Thanks Guillaume Malette)
5
+
1
6
  === Version 0.15.1 / 2013-7-11
2
7
  * Fixes
3
8
  * Fixed error when using sequential with entries that have spaces
data/data_magic.gemspec CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |gem|
7
7
  gem.platform = Gem::Platform::RUBY
8
8
  gem.authors = ["Jeff Morgan"]
9
9
  gem.email = ["jeff.morgan@leandog.com"]
10
+ gem.license = 'MIT'
10
11
  gem.homepage = "http://github.com/cheezy/data_magic"
11
12
  gem.summary = %q{Provides datasets to application via YAML files}
12
13
  gem.description = %q{Provides datasets to application stored in YAML files}
data/lib/data_magic.rb CHANGED
@@ -20,6 +20,7 @@ module DataMagic
20
20
  def data_for(key, additional={})
21
21
  DataMagic.load('default.yml') unless DataMagic.yml
22
22
  data = DataMagic.yml[key.to_s]
23
+ raise ArgumentError, "Undefined key #{key}" unless data
23
24
  prep_data data.merge(additional).clone
24
25
  end
25
26
 
@@ -28,7 +29,7 @@ module DataMagic
28
29
  def prep_data(data)
29
30
  data.each do |key, value|
30
31
  unless value.nil?
31
- next unless value.respond_to? '[]'
32
+ next if !value.respond_to?('[]') || value.is_a?(Numeric)
32
33
  data[key] = translate(value[1..-1]) if value[0,1] == "~"
33
34
  end
34
35
  end
@@ -271,15 +271,27 @@ module DataMagic
271
271
  private
272
272
 
273
273
  def set_index_variable(ary, value)
274
- parent.instance_variable_set(index_name(ary), value)
274
+ index_hash[index_name(ary)] = value
275
275
  end
276
276
 
277
277
  def index_variable_for(ary)
278
- parent.instance_variable_get(index_name(ary))
278
+ value = index_hash[index_name(ary)]
279
+ index_hash[index_name(ary)] = -1 unless value
280
+ index_hash[index_name(ary)]
279
281
  end
280
282
 
281
283
  def index_name(ary)
282
- "@private_#{ary[0]}#{ary[1]}_index".gsub(' ', '_').downcase
284
+ "#{ary[0]}#{ary[1]}_index".gsub(' ', '_').downcase
285
+ end
286
+
287
+ def index_hash
288
+ dh = data_hash[parent]
289
+ data_hash[parent] = {} unless dh
290
+ data_hash[parent]
291
+ end
292
+
293
+ def data_hash
294
+ $data_magic_data_hash ||= {}
283
295
  end
284
296
 
285
297
  def process(value)
@@ -1,3 +1,3 @@
1
1
  module DataMagic
2
- VERSION = "0.15.1"
2
+ VERSION = "0.15.2"
3
3
  end
@@ -250,6 +250,19 @@ describe "DataMagic translations" do
250
250
  end
251
251
  end
252
252
 
253
+ context "with numeric values" do
254
+ it "doesn't translate values" do
255
+ set_field_value(1)
256
+ example.data_for("key").should have_field_value 1
257
+ end
258
+ end
259
+
260
+ context "with values not in the yaml" do
261
+ it "throws a ArgumentError" do
262
+ expect { example.data_for("inexistant_key") }.to raise_error ArgumentError
263
+ end
264
+ end
265
+
253
266
  context "providing date values" do
254
267
  it "should provide today's date" do
255
268
  set_field_value '~today'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_magic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.15.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-11 00:00:00.000000000 Z
11
+ date: 2013-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faker
@@ -103,7 +103,8 @@ files:
103
103
  - spec/lib/translation_spec.rb
104
104
  - spec/spec_helper.rb
105
105
  homepage: http://github.com/cheezy/data_magic
106
- licenses: []
106
+ licenses:
107
+ - MIT
107
108
  metadata: {}
108
109
  post_install_message:
109
110
  rdoc_options: []