Class: Springcm::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/springcm-sdk/object.rb

Instance Method Summary collapse

Constructor Details

#initialize(data, client) ⇒ Object

Returns a new instance of Object.



3
4
5
6
# File 'lib/springcm-sdk/object.rb', line 3

def initialize(data, client)
  @client = client
  @data = data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Retrieve a top-level property of the object’s JSON data.

For convenience, top-level properties of a SpringCM object’s JSON data are accessible via instance methods (underscore format), e.g. attribute_groups to retrieve JSON for $.AttributeGroups. This can be and is often overridden by inheriting classes by defining a method and extending what it does. Some mixins also provide convenience methods for retrieving data deeper in the JSON document, e.g. documents_href via Springcm::Mixins::Documents.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/springcm-sdk/object.rb', line 17

def method_missing(m, *args, &block)
  mode = :get
  method = m.to_s
  if method.end_with?("=")
    mode = :set
    method = method[0...-1]
  end
  key = method.split("_").map(&:capitalize).join
  if @data.key?(key)
    if mode == :get
      @data.fetch(key)
    else
      @data[key] = args.first
    end
  else
    super
  end
end

Instance Method Details

#rawObject

Retrieve the raw JSON document for this object.



37
38
39
# File 'lib/springcm-sdk/object.rb', line 37

def raw
  @data
end