Module: Contentful::Resource::ClassMethods

Defined in:
lib/contentful/resource.rb

Overview

Register the resources properties on class level by using the #property method

Instance Method Summary (collapse)

Instance Method Details

- (Object) property(name, property_class = nil)

Defines which properties of a resource your class expects Define them in :camelCase, they will be available as #snake_cased methods

You can pass in a second "type" argument:

  • If it is a class, it will be initialized for the property

  • Symbols are looked up in the COERCION constant for a lambda that defines a type conversion to apply

Note: This second argument is not meant for contentful sub-resources, but for structured objects (like locales in a space) Sub-resources are handled by the resource builder



92
93
94
95
96
97
# File 'lib/contentful/resource.rb', line 92

def property(name, property_class = nil)
  property_coercions[name.to_sym] = property_class
  define_method Contentful::Support.snakify(name) do
    properties[name.to_sym]
  end
end

- (Object) property_coercions



77
78
79
# File 'lib/contentful/resource.rb', line 77

def property_coercions
  @property_coercions ||= {}
end