acts-as-optionable 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -40,6 +40,14 @@ class Option < ActiveRecord::Base
40
40
  name.humanize.titleize
41
41
  end
42
42
 
43
+ def to_h
44
+ option_hash = {}
45
+ option_hash["value"] = value
46
+ option_hash["default"] = default if default
47
+ option_hash["kind"] = kind if kind
48
+ option_hash.dup
49
+ end
50
+
43
51
  # def default_value
44
52
  # @config['default']
45
53
  # end
@@ -48,17 +48,12 @@ module ActiveRecord
48
48
  # Return a pure hash filled from the options. Use this if you want access to the data
49
49
  # as a hash without interfacing with Option methods
50
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
51
+ options_and_defaults.inject({}) do |memo, option|
52
+ memo[option[0]] = option[1].to_h
53
+ memo
58
54
  end
59
- options
60
55
  end
61
-
56
+
62
57
  # Returns an instance of options where option names are callable as methods
63
58
  #
64
59
  # Example:
@@ -69,8 +64,9 @@ module ActiveRecord
69
64
  def options_values_struct
70
65
  options = {}
71
66
  options_and_defaults.each do |name, option|
72
- options[name.to_s] = option.value
73
- options["#{name.to_s}_kind"] = option.kind
67
+ opt_key = name.to_s
68
+ options[opt_key] = option.value
69
+ options["#{opt_key}_kind"] = option.kind
74
70
  end
75
71
  OpenStruct.new(options)
76
72
  end
@@ -5,7 +5,8 @@ module ActiveRecord
5
5
  module ClassMethods
6
6
  # Setup a default value at the class level.
7
7
  def specify_option(option_name, opts = {})
8
- optionable_specified_options[option_name.to_s] = Option.new_readonly(:name => option_name.to_s, :default => opts[:default], :kind => opts[:kind])
8
+ name = option_name.to_s
9
+ optionable_specified_options[name] = Option.new_readonly(:name => name, :default => opts[:default], :kind => opts[:kind])
9
10
  end
10
11
 
11
12
  # Returns a hash of options specified at the class level
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 1
9
+ version: 0.3.1
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-28 00:00:00 -07:00
17
+ date: 2010-04-29 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies: []
20
20