Class: ActiveCMIS::AttributePrefix

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#objectObject (readonly)

Returns The object that the attribute getting and setting will take place on.

Returns:

  • (Object)

    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

#prefixString (readonly)

Returns:

  • (String)


7
8
9
# File 'lib/active_cmis/attribute_prefix.rb', line 7

def prefix
  @prefix
end