Class: Rumx::HashAttribute
- Defined in:
- lib/rumx/hash_attribute.rb
Instance Attribute Summary
Attributes inherited from Attribute
#allow_read, #allow_write, #description, #name, #type
Instance Method Summary collapse
- #each_attribute_info(bean, ancestry, &block) ⇒ Object
-
#initialize(name, type, description, allow_read, allow_write, options) ⇒ HashAttribute
constructor
A new instance of HashAttribute.
- #write?(bean, params) ⇒ Boolean
Methods inherited from Attribute
Constructor Details
#initialize(name, type, description, allow_read, allow_write, options) ⇒ HashAttribute
Returns a new instance of HashAttribute.
4 5 6 7 8 |
# File 'lib/rumx/hash_attribute.rb', line 4 def initialize(name, type, description, allow_read, allow_write, ) super raise 'Hash attribute called without hash_type option' unless [:hash_type] @hash_type = Type.find([:hash_type]) end |
Instance Method Details
#each_attribute_info(bean, ancestry, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rumx/hash_attribute.rb', line 10 def each_attribute_info(bean, ancestry, &block) hash = bean.send(name) return unless hash child_ancestry = ancestry+[name] index_index = child_ancestry.size hash.each do |name, value| value = nil unless allow_read child_ancestry[index_index] = name yield AttributeInfo.new(self, bean, child_ancestry, value) end end |
#write?(bean, params) ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rumx/hash_attribute.rb', line 22 def write?(bean, params) #puts "hash write params=#{params.inspect}" return false unless params.kind_of?(Hash) is_written = false if allow_write hash = bean.send(name) return false unless hash param_value(params) do |hash_params| if hash_params && hash_params.kind_of?(Hash) hash_params.each do |name, value| hash[name.to_sym] = @hash_type.string_to_value(value) is_written = true end end end end return is_written end |