Method: Contentful::Management::Resource::ClassMethods#property
- Defined in:
- lib/contentful/management/resource.rb
#property(name, property_class = nil) ⇒ Object
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
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/contentful/management/resource.rb', line 129 def property(name, property_class = nil) property_coercions[name.to_sym] = property_class accessor_name = Contentful::Management::Support.snakify(name) define_method accessor_name do properties[name.to_sym] end define_method "#{ accessor_name }=" do |value| properties[name.to_sym] = value end end |