Class: Rumx::Attribute
- Inherits:
-
Object
- Object
- Rumx::Attribute
- Defined in:
- lib/rumx/attribute.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#allow_read ⇒ Object
readonly
Returns the value of attribute allow_read.
-
#allow_write ⇒ Object
readonly
Returns the value of attribute allow_write.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #each_attribute_info(bean, ancestry) {|AttributeInfo.new(self, bean, ancestry+[@name], get_value(bean))| ... } ⇒ Object
- #get_value(bean) ⇒ Object
-
#initialize(name, type, description, allow_read, allow_write, options) ⇒ Attribute
constructor
A new instance of Attribute.
- #param_value(params, &block) ⇒ Object
- #write?(bean, params) ⇒ Boolean
Constructor Details
#initialize(name, type, description, allow_read, allow_write, options) ⇒ Attribute
Returns a new instance of Attribute.
5 6 7 8 9 10 11 12 13 |
# File 'lib/rumx/attribute.rb', line 5 def initialize(name, type, description, allow_read, allow_write, ) @name = name.to_sym @type = type @description = description # List and hash attributes might set up the object for reading but the individual elements for writing @allow_read = [:allow_read] || allow_read @allow_write = [:allow_write] || allow_write @options = end |
Instance Attribute Details
#allow_read ⇒ Object (readonly)
Returns the value of attribute allow_read.
3 4 5 |
# File 'lib/rumx/attribute.rb', line 3 def allow_read @allow_read end |
#allow_write ⇒ Object (readonly)
Returns the value of attribute allow_write.
3 4 5 |
# File 'lib/rumx/attribute.rb', line 3 def allow_write @allow_write end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
3 4 5 |
# File 'lib/rumx/attribute.rb', line 3 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/rumx/attribute.rb', line 3 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/rumx/attribute.rb', line 3 def type @type end |
Instance Method Details
#[](key) ⇒ Object
33 34 35 |
# File 'lib/rumx/attribute.rb', line 33 def [](key) @options[key] end |
#each_attribute_info(bean, ancestry) {|AttributeInfo.new(self, bean, ancestry+[@name], get_value(bean))| ... } ⇒ Object
19 20 21 |
# File 'lib/rumx/attribute.rb', line 19 def each_attribute_info(bean, ancestry, &block) yield AttributeInfo.new(self, bean, ancestry+[@name], get_value(bean)) end |
#get_value(bean) ⇒ Object
15 16 17 |
# File 'lib/rumx/attribute.rb', line 15 def get_value(bean) @allow_read ? bean.send(@name) : nil end |
#param_value(params, &block) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/rumx/attribute.rb', line 37 def param_value(params, &block) if params.has_key?(@name) yield params[@name] elsif params.has_key?(@name.to_s) yield params[@name.to_s] end end |
#write?(bean, params) ⇒ Boolean
23 24 25 26 27 28 29 30 31 |
# File 'lib/rumx/attribute.rb', line 23 def write?(bean, params) if @allow_write param_value(params) do |value| bean.send(@name.to_s+'=', @type.string_to_value(value)) return true end end return false end |