Class: Nemo::MetaObject::MultipleAttribute
Instance Attribute Summary
Attributes inherited from Attribute
#cache, #metaobject, #symbol, #validation_rules
Instance Method Summary
collapse
Methods inherited from Attribute
#add_validation_rule, #commit_cache, #error_class, #format, #required, #required?, #rule_class, #validate_cache, #value
#bool_accessor, #call_accessor, #proc_accessor
Constructor Details
Returns a new instance of MultipleAttribute.
164
165
166
167
168
169
|
# File 'lib/nemo/metaobject/attributes.rb', line 164
def initialize(symbol)
super
@multiple_attribute = true
@item_limit = 1_000_000
@item_delete = true
end
|
Instance Method Details
#accept(visitor) ⇒ Object
175
176
177
|
# File 'lib/nemo/metaobject/attributes.rb', line 175
def accept(visitor)
visitor.visit_multiple_attribute(self)
end
|
#add_required_rule ⇒ Object
171
172
173
|
# File 'lib/nemo/metaobject/attributes.rb', line 171
def add_required_rule
add_validation_rule { |value| ! value.to_s.empty? }.error_string('required')
end
|
#add_to_cache(item) ⇒ Object
183
184
185
186
|
# File 'lib/nemo/metaobject/attributes.rb', line 183
def add_to_cache(item)
@cache ||= Array.new
@cache << item
end
|
179
180
181
|
# File 'lib/nemo/metaobject/attributes.rb', line 179
def formatted_value
value.collect { |item| format(item) }
end
|
#refresh_cache ⇒ Object
188
189
190
191
|
# File 'lib/nemo/metaobject/attributes.rb', line 188
def refresh_cache
@cache = value.collect
@cache = @cache[0,@item_limit] if @cache.size > @item_limit
end
|
#remove_from_cache(item) ⇒ Object
193
194
195
|
# File 'lib/nemo/metaobject/attributes.rb', line 193
def remove_from_cache(item)
cache.delete(item)
end
|