Class: ActiveCMIS::AttributePrefix
- Inherits:
-
Object
- Object
- ActiveCMIS::AttributePrefix
- Defined in:
- lib/active_cmis/attribute_prefix.rb
Overview
A class used to get and set attributes that have a prefix like cmis: in their attribute IDs
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
The object that the attribute getting and setting will take place on.
- #prefix ⇒ String readonly
Instance Method Summary collapse
-
#initialize(object, prefix) ⇒ AttributePrefix
constructor
A new instance of AttributePrefix.
-
#method_missing(method, *parameters) ⇒ Object
For known attributes will act as a getter and setter.
Constructor Details
#initialize(object, prefix) ⇒ AttributePrefix
Returns a new instance of AttributePrefix.
10 11 12 13 |
# File 'lib/active_cmis/attribute_prefix.rb', line 10 def initialize(object, prefix) @object = object @prefix = prefix end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *parameters) ⇒ Object
For known attributes will act as a getter and setter
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/active_cmis/attribute_prefix.rb', line 16 def method_missing(method, *parameters) string = method.to_s if string[-1] == ?= assignment = true string = string[0..-2] end attribute = "#{prefix}:#{string}" if object.class.attributes.keys.include? attribute if assignment object.update(attribute => parameters.first) else object.attribute(attribute) end else # TODO: perhaps here we should try to look a bit further to see if there is a second : super end end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns The object that the attribute getting and setting will take place on.
5 6 7 |
# File 'lib/active_cmis/attribute_prefix.rb', line 5 def object @object end |
#prefix ⇒ String (readonly)
7 8 9 |
# File 'lib/active_cmis/attribute_prefix.rb', line 7 def prefix @prefix end |