embedded_record 0.0.2 → 0.0.3
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/embedded_record.rb +6 -5
- data/test/embedded_record_test.rb +2 -2
- metadata +1 -1
data/lib/embedded_record.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module EmbeddedRecord
|
2
|
-
VERSION = "0.0.
|
2
|
+
VERSION = "0.0.3"
|
3
3
|
|
4
4
|
def self.included(klass)
|
5
5
|
klass.extend self
|
@@ -10,7 +10,7 @@ module EmbeddedRecord
|
|
10
10
|
# - :class - Class to embed
|
11
11
|
# - :scope - Boolean wheter to install ActiveRecord scope
|
12
12
|
def embed_record(name, options = {})
|
13
|
-
klass = options[:class] || EmbeddedRecord.constantize(name)
|
13
|
+
klass = options[:class] || EmbeddedRecord.constantize(name.to_s)
|
14
14
|
attr = "#{name}_mask"
|
15
15
|
all = klass.all
|
16
16
|
|
@@ -50,8 +50,8 @@ module EmbeddedRecord
|
|
50
50
|
# end
|
51
51
|
#
|
52
52
|
def embed_records(name, options = {})
|
53
|
-
singular = options[:singular] || EmbeddedRecord.singularize(name)
|
54
|
-
klass = options[:class] || EmbeddedRecord.constantize(singular)
|
53
|
+
singular = options[:singular] || EmbeddedRecord.singularize(name.to_s)
|
54
|
+
klass = options[:class] || EmbeddedRecord.constantize(singular.to_s)
|
55
55
|
all_ids = klass.all.map { |obj| obj.id }
|
56
56
|
attr = "#{name}_mask"
|
57
57
|
|
@@ -105,7 +105,8 @@ private
|
|
105
105
|
|
106
106
|
def self.constantize(str)
|
107
107
|
if defined?(ActiveSupport::Inflector)
|
108
|
-
return ActiveSupport::Inflector.constantize(
|
108
|
+
return ActiveSupport::Inflector.constantize(
|
109
|
+
ActiveSupport::Inflector.classify(str))
|
109
110
|
end
|
110
111
|
|
111
112
|
# Stolen from ActiveSupport::Inflector
|
@@ -86,7 +86,7 @@ end
|
|
86
86
|
|
87
87
|
class Car
|
88
88
|
include EmbeddedRecord
|
89
|
-
embed_record :color
|
89
|
+
embed_record :color
|
90
90
|
attr_accessor :color_mask
|
91
91
|
end
|
92
92
|
|
@@ -113,7 +113,7 @@ end
|
|
113
113
|
|
114
114
|
class Shirt
|
115
115
|
include EmbeddedRecord
|
116
|
-
embed_records :colors
|
116
|
+
embed_records :colors
|
117
117
|
attr_accessor :colors_mask
|
118
118
|
end
|
119
119
|
|