hash_dealer 1.4.10 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/VERSION +1 -1
  2. data/coverage/assets/0.5.3/app.js +88 -0
  3. data/coverage/assets/0.5.3/fancybox/blank.gif +0 -0
  4. data/coverage/assets/0.5.3/fancybox/fancy_close.png +0 -0
  5. data/coverage/assets/0.5.3/fancybox/fancy_loading.png +0 -0
  6. data/coverage/assets/0.5.3/fancybox/fancy_nav_left.png +0 -0
  7. data/coverage/assets/0.5.3/fancybox/fancy_nav_right.png +0 -0
  8. data/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png +0 -0
  9. data/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png +0 -0
  10. data/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png +0 -0
  11. data/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png +0 -0
  12. data/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png +0 -0
  13. data/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png +0 -0
  14. data/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png +0 -0
  15. data/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png +0 -0
  16. data/coverage/assets/0.5.3/fancybox/fancy_title_left.png +0 -0
  17. data/coverage/assets/0.5.3/fancybox/fancy_title_main.png +0 -0
  18. data/coverage/assets/0.5.3/fancybox/fancy_title_over.png +0 -0
  19. data/coverage/assets/0.5.3/fancybox/fancy_title_right.png +0 -0
  20. data/coverage/assets/0.5.3/fancybox/fancybox-x.png +0 -0
  21. data/coverage/assets/0.5.3/fancybox/fancybox-y.png +0 -0
  22. data/coverage/assets/0.5.3/fancybox/fancybox.png +0 -0
  23. data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css +363 -0
  24. data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js +44 -0
  25. data/coverage/assets/0.5.3/favicon_green.png +0 -0
  26. data/coverage/assets/0.5.3/favicon_red.png +0 -0
  27. data/coverage/assets/0.5.3/favicon_yellow.png +0 -0
  28. data/coverage/assets/0.5.3/highlight.css +129 -0
  29. data/coverage/assets/0.5.3/highlight.pack.js +1 -0
  30. data/coverage/assets/0.5.3/jquery-1.6.2.min.js +18 -0
  31. data/coverage/assets/0.5.3/jquery.dataTables.min.js +152 -0
  32. data/coverage/assets/0.5.3/jquery.timeago.js +141 -0
  33. data/coverage/assets/0.5.3/jquery.url.js +174 -0
  34. data/coverage/assets/0.5.3/loading.gif +0 -0
  35. data/coverage/assets/0.5.3/magnify.png +0 -0
  36. data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  37. data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  38. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  39. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  40. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  41. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  42. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  43. data/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  44. data/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png +0 -0
  45. data/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  46. data/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png +0 -0
  47. data/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png +0 -0
  48. data/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  49. data/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css +295 -0
  50. data/coverage/assets/0.5.3/stylesheet.css +383 -0
  51. data/coverage/index.html +3777 -0
  52. data/hash_dealer.gemspec +4 -24
  53. data/lib/hash.rb +34 -0
  54. data/lib/hash_dealer.rb +24 -4
  55. data/pkg/hash_dealer-1.4.10.gem +0 -0
  56. data/spec/lib/hash_dealer_spec.rb +18 -0
  57. metadata +59 -11
  58. data/.document +0 -5
  59. data/.rspec +0 -3
data/hash_dealer.gemspec CHANGED
@@ -5,39 +5,19 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "hash_dealer"
8
- s.version = "1.4.10"
8
+ s.version = "1.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dan Langevin"]
12
- s.date = "2012-12-03"
12
+ s.date = "2012-12-27"
13
13
  s.description = "Like Factory Girl but for Hashes only"
14
14
  s.email = "dan.langevin@lifebooker.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.rdoc"
18
18
  ]
19
- s.files = [
20
- ".document",
21
- ".rspec",
22
- "Gemfile",
23
- "Gemfile.lock",
24
- "Guardfile",
25
- "LICENSE.txt",
26
- "README.rdoc",
27
- "Rakefile",
28
- "VERSION",
29
- "hash_dealer.gemspec",
30
- "lib/comparator.rb",
31
- "lib/core_extensions.rb",
32
- "lib/hash_dealer.rb",
33
- "lib/matcher.rb",
34
- "lib/path_string.rb",
35
- "lib/variable_array.rb",
36
- "spec/lib/hash_dealer_spec.rb",
37
- "spec/lib/matcher_spec.rb",
38
- "spec/lib/path_string_spec.rb",
39
- "spec/spec_helper.rb"
40
- ]
19
+ s.files = Dir["**/*"]
20
+
41
21
  s.homepage = "http://github.com/LifebookerInc/hash_dealer"
42
22
  s.licenses = ["MIT"]
43
23
  s.require_paths = ["lib"]
data/lib/hash.rb ADDED
@@ -0,0 +1,34 @@
1
+ class HashDealer
2
+ class Hash < ::Hash
3
+
4
+ def initialize(optional_attributes = [])
5
+ @optional_attributes = optional_attributes
6
+ end
7
+
8
+ def eql?(other)
9
+ self_for_comparison = self.remove_optional_keys(self)
10
+ other_for_comparison = self.remove_optional_keys(other)
11
+
12
+ self_for_comparison.eql?(other_for_comparison)
13
+ end
14
+
15
+ def to_hash
16
+ ret = ::Hash.new
17
+ self.each_pair do |k,v|
18
+ ret[k] = v
19
+ end
20
+ ret
21
+ end
22
+
23
+ protected
24
+
25
+ def remove_optional_keys(hash)
26
+ hash = hash.clone.to_hash
27
+ @optional_attributes.each do |optional_attribute|
28
+ hash.delete(optional_attribute)
29
+ end
30
+ hash
31
+ end
32
+
33
+ end
34
+ end
data/lib/hash_dealer.rb CHANGED
@@ -5,10 +5,12 @@ require File.expand_path('../variable_array', __FILE__)
5
5
  require File.expand_path('../core_extensions', __FILE__)
6
6
  require File.expand_path('../matcher', __FILE__)
7
7
  require File.expand_path('../comparator', __FILE__)
8
+ require File.expand_path('../hash', __FILE__)
8
9
 
9
10
  class HashDealer
10
11
 
11
12
  attr_accessor :parent
13
+ attr_accessor :optional_attributes
12
14
 
13
15
  # cattr_accessor
14
16
  def self.hashes
@@ -30,6 +32,7 @@ class HashDealer
30
32
  # initializer just calls the block from within our DSL
31
33
  def initialize(opts = {}, &block)
32
34
  @parent = opts[:parent]
35
+ @optional_attributes = []
33
36
  instance_eval(&block)
34
37
  end
35
38
 
@@ -46,7 +49,13 @@ class HashDealer
46
49
  def _attributes(overrides)
47
50
  # allows us to set a root value
48
51
  return @attributes.clone unless @attributes.is_a?(Hash)
49
- att = @parent ? HashDealer.roll(@parent.to_sym) : Hash.new
52
+
53
+ if @parent.present?
54
+ att = HashDealer.roll(@parent.to_sym)
55
+ else
56
+ att = HashDealer::Hash.new(self.optional_attributes)
57
+ end
58
+
50
59
  @attributes.each do |k,v|
51
60
  att[k] = v.is_a?(Proc) ? v.call(att.merge(overrides)) : v
52
61
  end
@@ -60,13 +69,24 @@ class HashDealer
60
69
  protected
61
70
 
62
71
  # method missing
63
- def method_missing(meth, *args, &block)
64
- raise Exception.new("Please provide either a String or a block to #{meth}") unless (args.length == 1 || (args.empty? && block_given?))
72
+ def method_missing(meth, value = nil, opts = {}, &block)
73
+
74
+ unless value.present? || block_given?
75
+ raise Exception.new(
76
+ "Please provide either a String or a block to #{meth}"
77
+ )
78
+ end
79
+
80
+ if opts[:optional]
81
+ @optional_attributes << meth.to_sym
82
+ end
83
+
65
84
  @attributes ||= Hash.new
85
+
66
86
  if block_given?
67
87
  @attributes[meth.to_sym] = block
68
88
  else
69
- @attributes[meth.to_sym] = args.first
89
+ @attributes[meth.to_sym] = value
70
90
  end
71
91
  end
72
92
  end
Binary file
@@ -221,6 +221,24 @@ describe HashDealer do
221
221
 
222
222
  end
223
223
 
224
+ context "optional values" do
225
+
226
+ it "should allow values to be optionally passed in" do
227
+ HashDealer.define(:with_optional_values) do
228
+ required_value "x"
229
+ optional_value "y", :optional => true
230
+ end
231
+
232
+ hd = HashDealer.roll(:with_optional_values)
233
+
234
+ hd.should eql({:required_value => "x"})
235
+ hd.should eql({:required_value => "x", :optional_value => "y"})
236
+ hd.should_not eql({:optional_value => "y"})
237
+ hd.should_not eql({:required_value => "x", :bad_value => "z"})
238
+
239
+ end
240
+
241
+ end
224
242
 
225
243
 
226
244
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_dealer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.10
4
+ version: 1.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-03 00:00:00.000000000 Z
12
+ date: 2012-12-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -179,26 +179,76 @@ extra_rdoc_files:
179
179
  - LICENSE.txt
180
180
  - README.rdoc
181
181
  files:
182
- - .document
183
- - .rspec
182
+ - coverage/assets/0.5.3/app.js
183
+ - coverage/assets/0.5.3/fancybox/blank.gif
184
+ - coverage/assets/0.5.3/fancybox/fancy_close.png
185
+ - coverage/assets/0.5.3/fancybox/fancy_loading.png
186
+ - coverage/assets/0.5.3/fancybox/fancy_nav_left.png
187
+ - coverage/assets/0.5.3/fancybox/fancy_nav_right.png
188
+ - coverage/assets/0.5.3/fancybox/fancy_shadow_e.png
189
+ - coverage/assets/0.5.3/fancybox/fancy_shadow_n.png
190
+ - coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png
191
+ - coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png
192
+ - coverage/assets/0.5.3/fancybox/fancy_shadow_s.png
193
+ - coverage/assets/0.5.3/fancybox/fancy_shadow_se.png
194
+ - coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png
195
+ - coverage/assets/0.5.3/fancybox/fancy_shadow_w.png
196
+ - coverage/assets/0.5.3/fancybox/fancy_title_left.png
197
+ - coverage/assets/0.5.3/fancybox/fancy_title_main.png
198
+ - coverage/assets/0.5.3/fancybox/fancy_title_over.png
199
+ - coverage/assets/0.5.3/fancybox/fancy_title_right.png
200
+ - coverage/assets/0.5.3/fancybox/fancybox-x.png
201
+ - coverage/assets/0.5.3/fancybox/fancybox-y.png
202
+ - coverage/assets/0.5.3/fancybox/fancybox.png
203
+ - coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css
204
+ - coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js
205
+ - coverage/assets/0.5.3/favicon_green.png
206
+ - coverage/assets/0.5.3/favicon_red.png
207
+ - coverage/assets/0.5.3/favicon_yellow.png
208
+ - coverage/assets/0.5.3/highlight.css
209
+ - coverage/assets/0.5.3/highlight.pack.js
210
+ - coverage/assets/0.5.3/jquery-1.6.2.min.js
211
+ - coverage/assets/0.5.3/jquery.dataTables.min.js
212
+ - coverage/assets/0.5.3/jquery.timeago.js
213
+ - coverage/assets/0.5.3/jquery.url.js
214
+ - coverage/assets/0.5.3/loading.gif
215
+ - coverage/assets/0.5.3/magnify.png
216
+ - coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
217
+ - coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
218
+ - coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
219
+ - coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
220
+ - coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png
221
+ - coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
222
+ - coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
223
+ - coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
224
+ - coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png
225
+ - coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png
226
+ - coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png
227
+ - coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png
228
+ - coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png
229
+ - coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css
230
+ - coverage/assets/0.5.3/stylesheet.css
231
+ - coverage/index.html
184
232
  - Gemfile
185
233
  - Gemfile.lock
186
234
  - Guardfile
187
- - LICENSE.txt
188
- - README.rdoc
189
- - Rakefile
190
- - VERSION
191
235
  - hash_dealer.gemspec
192
236
  - lib/comparator.rb
193
237
  - lib/core_extensions.rb
238
+ - lib/hash.rb
194
239
  - lib/hash_dealer.rb
195
240
  - lib/matcher.rb
196
241
  - lib/path_string.rb
197
242
  - lib/variable_array.rb
243
+ - LICENSE.txt
244
+ - pkg/hash_dealer-1.4.10.gem
245
+ - Rakefile
246
+ - README.rdoc
198
247
  - spec/lib/hash_dealer_spec.rb
199
248
  - spec/lib/matcher_spec.rb
200
249
  - spec/lib/path_string_spec.rb
201
250
  - spec/spec_helper.rb
251
+ - VERSION
202
252
  homepage: http://github.com/LifebookerInc/hash_dealer
203
253
  licenses:
204
254
  - MIT
@@ -212,9 +262,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
212
262
  - - ! '>='
213
263
  - !ruby/object:Gem::Version
214
264
  version: '0'
215
- segments:
216
- - 0
217
- hash: 4440880840768368962
218
265
  required_rubygems_version: !ruby/object:Gem::Requirement
219
266
  none: false
220
267
  requirements:
@@ -228,3 +275,4 @@ signing_key:
228
275
  specification_version: 3
229
276
  summary: Hash Factory - like Factory Girl but for Hashes only
230
277
  test_files: []
278
+ has_rdoc:
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --format nested
3
- --backtrace