data_magic 0.14 → 0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 922557a61172c1af98da3f9540fc53cb0e893012
4
+ data.tar.gz: dac1c4381d65cc8da7a196931276309f97c59634
5
+ SHA512:
6
+ metadata.gz: d23ffb5d15323112f045709476b077a0ea11830197345c026bc3a81e600a6b7ed325c7e709fe2d22b7b90d67d643897ca84d9ad270aba6e05f48306655cff76d
7
+ data.tar.gz: dee63c85fd6a0f31bb4dc26078b2acadf0e5ae72eae2ba0665397819f0aa40a47565023e2c65046a981f5b12ffcec382f87dc98d048f1c0f3bfd336740fdc079
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
1
  --color
2
- --format Fuubar
2
+ --format documentation
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ data_magic
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p195
data/.travis.yml CHANGED
@@ -3,5 +3,6 @@ rvm:
3
3
  - 1.8.7
4
4
  - 1.9.2
5
5
  - 1.9.3
6
+ - 2.0.0
6
7
  - rbx-19mode
7
- - ree
8
+
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ === Version 0.15 / 2013-7-10
2
+ * Enhancements
3
+ * Added sequential translator
4
+
1
5
  === Version 0.14 / 2013-2-14
2
6
  * Enhancements
3
7
  * Added months_abbr translator
data/Gemfile CHANGED
@@ -1,12 +1,11 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gem 'rake'
4
- gem 'fuubar'
5
- gem 'fuubar-cucumber'
6
4
  gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
7
5
  gem 'growl'
8
6
  gem 'guard-rspec'
9
7
  gem 'guard-cucumber'
8
+ gem 'fuubar'
10
9
 
11
10
  # Specify your gem's dependencies in data_magic.gemspec
12
11
  gemspec
data/Guardfile CHANGED
@@ -3,11 +3,11 @@
3
3
 
4
4
  guard 'rspec', :cli => '--color --format Fuubar' do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
6
+ watch(%r{^lib/(.+)\.rb$}) { "spec" }
7
7
  watch('spec/spec_helper.rb') { "spec" }
8
8
  end
9
9
 
10
- guard 'cucumber', :notification => true, :cli => '--profile default' do
10
+ guard 'cucumber', :notification => true, :cli => '--profile focus' do
11
11
  watch(%r{^features/.+\.feature$})
12
12
  watch(%r{^features/support/.+$}) { 'features' }
13
13
  watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
data/README.md CHANGED
@@ -65,6 +65,47 @@ You can call one of many built-in methods in your yaml file to randomize the dat
65
65
  email: ~email_address
66
66
  pay_type: ~randomize ['Credit card', 'Purchase order', 'Check']
67
67
 
68
+ Here is a list of the built-in methods:
69
+
70
+ | built-in methods | built-in methods |
71
+ | --- | --- |
72
+ | first_name last_name |
73
+ | last_name | full_name |
74
+ | name_prefix | name_suffix |
75
+ | title | street_address(include_secondary=false) |
76
+ | secondary_address | city |
77
+ | state | state_abbr |
78
+ | zip_code | country |
79
+ | company_name | catch_phrase |
80
+ | words(number = 3) | sentence(min_word_count = 4) |
81
+ | sentences(sentence_count = 3) | paragraphs(paragraph_count = 3) |
82
+ | characters(character_count = 255) | email_address(name = nil) |
83
+ | domain_name | url |
84
+ | user_name |
85
+ | phone_number | cell_phone |
86
+ | randomize([]) | randomize(1..4) |
87
+ | mask - #=num a=lower A=upper |
88
+ | today(format = '%D') | tomorrow(format = '%D') |
89
+ | yesterday(format = '%D') |
90
+ | 3.days_from_today(format = '%D') | 3.days_ago(format = '%D') |
91
+ | month | month_abbr |
92
+ | day_of_week | day_of_week_abbr |
93
+
94
+
95
+ If you wish to add your own built-in methods you can simply pass a module
96
+ to _DataMagic_ and all of the methods will be available.
97
+
98
+ ````ruby
99
+ module MyData
100
+ def abc
101
+ 'abc'
102
+ end
103
+ end
104
+
105
+ DataMagic.add_translator MyData
106
+
107
+ # can now use ~abc in my yml files
108
+ ````
68
109
 
69
110
  ## Documentation
70
111
 
@@ -90,4 +131,4 @@ Please ensure all contributions contain proper tests.
90
131
 
91
132
  ## Copyright
92
133
 
93
- Copyright (c) 2012 Jeffrey S. Morgan. See LICENSE for details.
134
+ Copyright (c) 2012-2013 Jeffrey S. Morgan. See LICENSE for details.
data/cucumber.yml CHANGED
@@ -1 +1,2 @@
1
- default: --no-source --color --format Cucumber::Formatter::Fuubar
1
+ default: --no-source --color --format pretty
2
+ focus: --no-source --color --format pretty --tags @focus
@@ -78,6 +78,13 @@ Feature: Functionality of the data_magic gem
78
78
  Then the value for "random" should be either "Tom", "Dick", or "Harry"
79
79
  And the value for "range" should be between 1 and 5
80
80
 
81
+ Scenario: Returning a sequential value from an array
82
+ Then the first value for the sequential data should be "first"
83
+ When I ask for the data again
84
+ Then the second value for the sequential data should be "second"
85
+ When I ask for the data again
86
+ Then the third value for the sequential data should be "third"
87
+
81
88
  Scenario: Returning a value based on a mask
82
89
  Then the value for "mask" should begin with 3 numbers
83
90
  And the value for "mask" should have 3 upper case letters after a dash
@@ -13,7 +13,9 @@ Given /^I have read the default yaml file from the default location$/ do
13
13
  end
14
14
 
15
15
  When /^I ask for the data for "(.+)"$/ do |key|
16
- @data = TestClass.new.data_for key
16
+ TestClass.instance_variable_set "@private_firstsecond_index", 0
17
+ @tc = TestClass.new
18
+ @data = @tc.data_for key
17
19
  end
18
20
 
19
21
 
@@ -132,3 +134,11 @@ When /^I add the blah translator$/ do
132
134
  ta = TranslatorAdded.new
133
135
  @data = ta.data_for 'dynamic'
134
136
  end
137
+
138
+ Then(/^the (?:first|second|third) value for the sequential data should be "(.*?)"$/) do |value|
139
+ @data['ordered'].should == value
140
+ end
141
+
142
+ When(/^I ask for the data again$/) do
143
+ @data = @tc.data_for 'dm'
144
+ end
@@ -31,6 +31,7 @@ dm:
31
31
  bool_true: true
32
32
  bool_false: false
33
33
  random: ~randomize ['Tom', 'Dick', 'Harry']
34
+ ordered: ~sequential ['first', 'second', 'third']
34
35
  range: ~randomize 1..5
35
36
  mask: ~mask "###-AAA_aaa"
36
37
  title: ~title
data/lib/data_magic.rb CHANGED
@@ -8,7 +8,10 @@ require 'faker'
8
8
  module DataMagic
9
9
  extend YmlReader
10
10
 
11
+ attr_reader :parent
12
+
11
13
  def self.included(cls)
14
+ @parent = cls
12
15
  translators.each do |translator|
13
16
  Translation.send :include, translator
14
17
  end
@@ -33,7 +36,11 @@ module DataMagic
33
36
  end
34
37
 
35
38
  def translate(value)
36
- Translation.new.send :process, value
39
+ translation.send :process, value
40
+ end
41
+
42
+ def translation
43
+ @translation ||= Translation.new parent
37
44
  end
38
45
 
39
46
  class << self
@@ -3,7 +3,13 @@ require 'data_magic/date_translation'
3
3
  module DataMagic
4
4
  class Translation
5
5
  include DateTranslation
6
-
6
+
7
+ attr_reader :parent
8
+
9
+ def initialize(parent)
10
+ @parent = parent
11
+ end
12
+
7
13
  #
8
14
  # return a random name (first and last)
9
15
  #
@@ -227,6 +233,19 @@ module DataMagic
227
233
  end
228
234
  alias_method :dm_randomize, :randomize
229
235
 
236
+ #
237
+ # return an element from the array. The first request will return
238
+ # the first element, the second request will return the second,
239
+ # and so forth.
240
+ #
241
+ def sequential(value)
242
+ index = index_variable_for(value)
243
+ index = (index ? index + 1 : 0)
244
+ index = 0 if index == value.length
245
+ set_index_variable(value, index)
246
+ value[index]
247
+ end
248
+
230
249
  #
231
250
  # return a value based on a mast
232
251
  # The # character will be replaced with a number
@@ -251,6 +270,18 @@ module DataMagic
251
270
 
252
271
  private
253
272
 
273
+ def set_index_variable(ary, value)
274
+ parent.instance_variable_set(index_name(ary), value)
275
+ end
276
+
277
+ def index_variable_for(ary)
278
+ parent.instance_variable_get(index_name(ary))
279
+ end
280
+
281
+ def index_name(ary)
282
+ "@private_#{ary[0]}#{ary[1]}_index"
283
+ end
284
+
254
285
  def process(value)
255
286
  eval value
256
287
  end
@@ -1,3 +1,3 @@
1
1
  module DataMagic
2
- VERSION = "0.14"
2
+ VERSION = "0.15"
3
3
  end
metadata CHANGED
@@ -1,78 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_magic
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.14'
5
- prerelease:
4
+ version: '0.15'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jeff Morgan
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-15 00:00:00.000000000 Z
11
+ date: 2013-07-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: faker
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 1.1.2
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: 1.1.2
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: yml_reader
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.2'
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.2'
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: 2.12.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: 2.12.0
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: cucumber
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: 1.2.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: 1.2.0
78
69
  description: Provides datasets to application stored in YAML files
@@ -84,7 +75,8 @@ extra_rdoc_files: []
84
75
  files:
85
76
  - .gitignore
86
77
  - .rspec
87
- - .rvmrc
78
+ - .ruby-gemset
79
+ - .ruby-version
88
80
  - .travis.yml
89
81
  - ChangeLog
90
82
  - Gemfile
@@ -112,33 +104,26 @@ files:
112
104
  - spec/spec_helper.rb
113
105
  homepage: http://github.com/cheezy/data_magic
114
106
  licenses: []
107
+ metadata: {}
115
108
  post_install_message:
116
109
  rdoc_options: []
117
110
  require_paths:
118
111
  - lib
119
112
  required_ruby_version: !ruby/object:Gem::Requirement
120
- none: false
121
113
  requirements:
122
- - - ! '>='
114
+ - - '>='
123
115
  - !ruby/object:Gem::Version
124
116
  version: '0'
125
- segments:
126
- - 0
127
- hash: 2289410552337863128
128
117
  required_rubygems_version: !ruby/object:Gem::Requirement
129
- none: false
130
118
  requirements:
131
- - - ! '>='
119
+ - - '>='
132
120
  - !ruby/object:Gem::Version
133
121
  version: '0'
134
- segments:
135
- - 0
136
- hash: 2289410552337863128
137
122
  requirements: []
138
123
  rubyforge_project:
139
- rubygems_version: 1.8.24
124
+ rubygems_version: 2.0.3
140
125
  signing_key:
141
- specification_version: 3
126
+ specification_version: 4
142
127
  summary: Provides datasets to application via YAML files
143
128
  test_files:
144
129
  - features/data_magic.feature
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm 1.9.3-p194@data_magic --create