object_sugar 0.0.7 → 0.0.8
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.
- data/lib/object_sugar.rb +7 -5
- data/lib/object_sugar/version.rb +1 -1
- metadata +2 -2
data/lib/object_sugar.rb
CHANGED
@@ -33,7 +33,8 @@ module ObjectSugar
|
|
33
33
|
# Foo::MyConstants::THREE => tre
|
34
34
|
|
35
35
|
def create_constants(name, *args)
|
36
|
-
|
36
|
+
const = name.to_s.camelize.to_sym
|
37
|
+
klass = const_defined?(const) ? const_get(const) : const_set(name.to_s.camelize.to_sym, Class.new)
|
37
38
|
klass.extend ObjectSugar::InstanceMethods
|
38
39
|
|
39
40
|
args.flatten.each do |enum|
|
@@ -53,13 +54,14 @@ module ObjectSugar
|
|
53
54
|
# each subsequent argument in +args+ has a value +factor+^index
|
54
55
|
|
55
56
|
def create_enum(name, factor, *args)
|
56
|
-
|
57
|
+
const = name.to_s.camelize.to_sym
|
58
|
+
klass = const_defined?(const) ? const_get(const) : const_set(name.to_s.camelize.to_sym, Class.new)
|
57
59
|
klass.extend ObjectSugar::InstanceMethods
|
58
60
|
|
59
61
|
args.flatten.each_with_index { |const, index|
|
60
62
|
value = (factor == 1) ? (factor * index) : (factor.power!( index ))
|
61
63
|
|
62
|
-
klass.const_set(
|
64
|
+
klass.const_set(const.to_s.underscore.upcase, value.to_i)
|
63
65
|
}
|
64
66
|
|
65
67
|
klass
|
@@ -82,9 +84,9 @@ module ObjectSugar
|
|
82
84
|
|
83
85
|
def create_pluralized_constant(name)
|
84
86
|
pluralized = ActiveSupport::Inflector.pluralize( name.to_s ).upcase.to_sym
|
85
|
-
constants = const_get(
|
87
|
+
constants = const_get(name.to_s.camelize.to_sym).constants
|
86
88
|
|
87
|
-
const_set(
|
89
|
+
const_set(pluralized, constants) unless const_defined?(pluralized)
|
88
90
|
end
|
89
91
|
end
|
90
92
|
end
|
data/lib/object_sugar/version.rb
CHANGED