Class: Strapi::ContentType
- Inherits:
-
Object
- Object
- Strapi::ContentType
- Defined in:
- lib/strapi/content_type.rb
Overview
The class for defining a Ruby class that represents a Strapi Content-Type
Direct Known Subclasses
Class Attribute Summary collapse
-
.fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#deleted ⇒ Object
readonly
Returns the value of attribute deleted.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
- .all(params = {}) ⇒ Object
- .create(attributes, params = {}) ⇒ Object
- .field(attr, options = {}) ⇒ Object
- .find(id, params = {}) ⇒ Object
- .plural_id(name) ⇒ Object
- .where(params) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #delete(params = {}) ⇒ Object
-
#initialize(attributes = {}) ⇒ ContentType
constructor
A new instance of ContentType.
- #save(params = {}) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ ContentType
Returns a new instance of ContentType.
8 9 10 |
# File 'lib/strapi/content_type.rb', line 8 def initialize(attributes = {}) @attributes = attributes.symbolize_keys end |
Class Attribute Details
.fields ⇒ Object (readonly)
Returns the value of attribute fields.
78 79 80 |
# File 'lib/strapi/content_type.rb', line 78 def fields @fields end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/strapi/content_type.rb', line 6 def attributes @attributes end |
#deleted ⇒ Object (readonly)
Returns the value of attribute deleted.
6 7 8 |
# File 'lib/strapi/content_type.rb', line 6 def deleted @deleted end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/strapi/content_type.rb', line 6 def id @id end |
Class Method Details
.all(params = {}) ⇒ Object
101 102 103 |
# File 'lib/strapi/content_type.rb', line 101 def all(params = {}) get_list(params) end |
.create(attributes, params = {}) ⇒ Object
109 110 111 |
# File 'lib/strapi/content_type.rb', line 109 def create(attributes, params = {}) new(attributes).save(params) end |
.field(attr, options = {}) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/strapi/content_type.rb', line 84 def field(attr, = {}) @fields = [] if fields.nil? fields << attr define_method attr do strapi_attr_value(attr, ) end define_method "#{attr}=" do |value| attributes[attr] = value end end |
.find(id, params = {}) ⇒ Object
97 98 99 |
# File 'lib/strapi/content_type.rb', line 97 def find(id, params = {}) new_from_response Request.get("#{_plural_id}/#{id}", params).data end |
.plural_id(name) ⇒ Object
80 81 82 |
# File 'lib/strapi/content_type.rb', line 80 def plural_id(name) @_plural_id = name end |
.where(params) ⇒ Object
105 106 107 |
# File 'lib/strapi/content_type.rb', line 105 def where(params) get_list(params) end |
Instance Method Details
#==(other) ⇒ Object
18 19 20 |
# File 'lib/strapi/content_type.rb', line 18 def ==(other) other.is_a?(self.class) && id == other.id end |
#delete(params = {}) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/strapi/content_type.rb', line 33 def delete(params = {}) Request.delete("#{self.class.send(:_plural_id)}/#{id}", params) @attributes = {} @id = nil @deleted = true nil end |
#save(params = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/strapi/content_type.rb', line 22 def save(params = {}) return if deleted response = id ? update_request(params) : create_request(params) entry = self.class.send(:new_from_response, response) tap do @attributes = attributes.deep_merge entry.attributes @id = entry.id end end |