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(query_hash = {}) ⇒ Object
- .create(attributes, query_hash = {}) ⇒ Object
- .field(attr, options = {}) ⇒ Object
- .find(id, query_hash = {}) ⇒ Object
- .plural_id(name) ⇒ Object
- .where(query_hash) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #delete(query_hash = {}) ⇒ Object
-
#initialize(attributes = {}) ⇒ ContentType
constructor
A new instance of ContentType.
- #save(query_hash = {}) ⇒ 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(query_hash = {}) ⇒ Object
101 102 103 |
# File 'lib/strapi/content_type.rb', line 101 def all(query_hash = {}) get_list(query_hash) end |
.create(attributes, query_hash = {}) ⇒ Object
109 110 111 |
# File 'lib/strapi/content_type.rb', line 109 def create(attributes, query_hash = {}) new(attributes).save(query_hash) 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, query_hash = {}) ⇒ Object
97 98 99 |
# File 'lib/strapi/content_type.rb', line 97 def find(id, query_hash = {}) new_from_response Request.get("#{_plural_id}/#{id}?#{query_hash.to_query}").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(query_hash) ⇒ Object
105 106 107 |
# File 'lib/strapi/content_type.rb', line 105 def where(query_hash) get_list(query_hash) 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(query_hash = {}) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/strapi/content_type.rb', line 33 def delete(query_hash = {}) Request.delete("#{self.class.send(:_plural_id)}/#{id}?#{query_hash.to_query}") @attributes = {} @id = nil @deleted = true nil end |
#save(query_hash = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/strapi/content_type.rb', line 22 def save(query_hash = {}) return if deleted response = id ? update_request(query_hash) : create_request(query_hash) entry = self.class.send(:new_from_response, response) tap do @attributes = attributes.deep_merge entry.attributes @id = entry.id end end |