acts_as_itemized 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/acts_as_itemized.rb +31 -1
- metadata +1 -1
data/lib/acts_as_itemized.rb
CHANGED
@@ -72,9 +72,39 @@ module ActsAsItemized
|
|
72
72
|
super
|
73
73
|
end
|
74
74
|
|
75
|
+
def each_itemized(*args, &block)
|
76
|
+
# item_type
|
77
|
+
type_many = args.first
|
78
|
+
type_one = type_many.to_s.singularize
|
79
|
+
# options
|
80
|
+
options = args.extract_options!
|
81
|
+
options.assert_valid_keys(:columns)
|
82
|
+
# itemized_options
|
83
|
+
itemized_option = self.itemized_options[type_many]
|
84
|
+
count = itemized_option[:count]
|
85
|
+
columns = options[:columns] || itemized_option[:columns]
|
86
|
+
# iterate
|
87
|
+
result = []
|
88
|
+
columns.each do |column|
|
89
|
+
count.times do |i|
|
90
|
+
pos = i + 1
|
91
|
+
# build key
|
92
|
+
key = type_one
|
93
|
+
key = "#{key}_#{column}_#{pos}" unless count == 1 && columns.count == 1
|
94
|
+
# pass key
|
95
|
+
if block_given?
|
96
|
+
result << yield(key)
|
97
|
+
else
|
98
|
+
result << self.send(key)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
result
|
103
|
+
end
|
104
|
+
|
75
105
|
|
76
106
|
protected
|
77
|
-
|
107
|
+
|
78
108
|
# ITEM CHANGES
|
79
109
|
def itemize(*args)
|
80
110
|
args.each do |arg|
|