active_delegate 0.1.3 → 0.1.4
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.
- checksums.yaml +4 -4
- data/lib/active_delegate/attributes.rb +8 -5
- data/lib/active_delegate/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b25f154bc3bf1b847b20e9b4b410523881d47f1
|
4
|
+
data.tar.gz: 99f6ddd155f8d6e52fc72d0de2fab400604366a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a37d3dc37ab0f5a6bc55ba414179758c470e73cd8dbf95df474e8783f7b262abd2d59b69cb961582de5aad7dd997b84ac46b62549e5f96d76c35dba65959490f
|
7
|
+
data.tar.gz: f8fe8f1bcec56fda65430bc519d05d5092c66b46dfa0ecaea64a70f2c17ad7ba66825fee08591e89c4b6c309344a7fbc4f9817fc227e5cbae8ed8e8fa5b2dfdb
|
@@ -102,13 +102,16 @@ module ActiveDelegate
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
+
# Get attribute prefix
|
106
|
+
def attribute_prefix
|
107
|
+
prefix = @options[:prefix]
|
108
|
+
prefix.is_a?(TrueClass) ? @options[:to] : prefix
|
109
|
+
end
|
110
|
+
|
105
111
|
# Get prefixed attributes
|
106
112
|
def prefix_attributes(attributes)
|
107
113
|
if @options[:prefix].present?
|
108
|
-
|
109
|
-
prefix = @options[:to] if prefix.is_a? TrueClass
|
110
|
-
|
111
|
-
attributes.map { |a| :"#{prefix}_#{a}" }
|
114
|
+
attributes.map { |a| :"#{attribute_prefix}_#{a}" }
|
112
115
|
else
|
113
116
|
attributes
|
114
117
|
end
|
@@ -134,7 +137,7 @@ module ActiveDelegate
|
|
134
137
|
# Define attribute names and types
|
135
138
|
def define_attribute_names_and_types(attributes)
|
136
139
|
attributes.each do |attrib|
|
137
|
-
attr_name = attrib.to_s.sub("#{
|
140
|
+
attr_name = attrib.to_s.sub("#{attribute_prefix}_", '')
|
138
141
|
cast_type = association_class.attribute_types["#{attr_name}"]
|
139
142
|
|
140
143
|
@model.attribute(attrib, cast_type) unless cast_type.nil?
|