acts-as-optionable 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -40,10 +40,25 @@ module ActiveRecord
40
40
  end
41
41
  end
42
42
 
43
+ # Return a hash of options and defaults. Values in hash are Option instances
43
44
  def options_and_defaults
44
45
  get_default_options.merge(options_as_hash)
45
46
  end
46
47
 
48
+ # Return a pure hash filled from the options. Use this if you want access to the data
49
+ # as a hash without interfacing with Option methods
50
+ def options_and_defaults_hash
51
+ options = {}
52
+ options_and_defaults.each do |name, option|
53
+ key = name.to_s
54
+ options[key] = {}
55
+ options[key]["value"] = option.value
56
+ options[key]["default"] = option.default if option.default
57
+ options[key]["kind"] = option.kind if option.kind
58
+ end
59
+ options
60
+ end
61
+
47
62
  # Returns an instance of options where option names are callable as methods
48
63
  #
49
64
  # Example:
@@ -295,4 +295,29 @@ describe "ActsAsOptionable" do
295
295
  option_values.example_option.should == 99
296
296
  end
297
297
  end
298
+
299
+ describe "getting options and defaults as a hash" do
300
+ before(:each) do
301
+ @optionable.set_option("example_option", "example_value")
302
+ @options_and_defaults_hash = @optionable.options_and_defaults_hash
303
+ end
304
+
305
+ it "should return a hash" do
306
+ @options_and_defaults_hash.should be_kind_of(Hash)
307
+ end
308
+
309
+ it "should have a value set for default options" do
310
+ @options_and_defaults_hash["foo"]["value"].should == "FOOFOO"
311
+ @options_and_defaults_hash["bar"]["value"].should == "BARBAR"
312
+ end
313
+
314
+ it "should return non-default options as well" do
315
+ @options_and_defaults_hash["example_option"]["value"].should == "example_value"
316
+ end
317
+
318
+ it "should include the kind and default" do
319
+ @options_and_defaults_hash["bar"]["default"].should == "BARBAR"
320
+ @options_and_defaults_hash["bar"]["kind"].should == "example"
321
+ end
322
+ end
298
323
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 1
9
- version: 0.2.1
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brendon Murphy
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-27 00:00:00 -07:00
17
+ date: 2010-04-28 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies: []
20
20