Module: CMIS::Helpers

Included in:
Object
Defined in:
lib/cmis/helpers.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object


36
37
38
39
40
41
42
# File 'lib/cmis/helpers.rb', line 36

def method_missing(name, *args, &block)
  if @properties.has_key?(name.to_s)
    @properties[name.to_s]
  else
    super
  end
end

Instance Method Details

#cmis_properties(properties) ⇒ Object


7
8
9
10
11
12
13
14
15
# File 'lib/cmis/helpers.rb', line 7

def cmis_properties(properties)
  properties.each do |property_name|
    method_name = method_name(property_name)
    self.class.class_eval "def #{method_name};@properties['#{property_name}'];end"
    self.class.class_eval "def #{method_name}=(value);@properties['#{property_name}']=value;end"
  end
rescue Exception => e
  raise "Unable to generate accessors for properties: #{properties}"
end

#initialize_properties(raw) ⇒ Object


3
4
5
# File 'lib/cmis/helpers.rb', line 3

def initialize_properties(raw)
  @properties = get_properties_map(raw)
end

#respond_to?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)

28
29
30
31
32
33
34
# File 'lib/cmis/helpers.rb', line 28

def respond_to?(name, include_private = false)
  if @properties.has_key?(name.to_s)
    true
  else
    super
  end
end

#with_change_token(&block) ⇒ Object


17
18
19
20
21
22
23
24
25
26
# File 'lib/cmis/helpers.rb', line 17

def with_change_token(&block)
  json = yield
  if props = json['properties']
    self.change_token = props['cmis:changeToken']['value']
  elsif succinct_props = json['succinctProperties']
    self.change_token = succinct_props['cmis:changeToken']
  else
    raise "Unexpected input: #{json}"
  end
end