Class: Delighted::Resource
- Inherits:
-
Object
- Object
- Delighted::Resource
- Defined in:
- lib/delighted/resource.rb
Direct Known Subclasses
AutopilotConfiguration, AutopilotMembership, Bounce, Metrics, Person, SurveyRequest, SurveyResponse, Unsubscribe
Class Attribute Summary collapse
- .expandable_attributes ⇒ Object
-
.path ⇒ Object
Returns the value of attribute path.
-
.singleton_resource ⇒ Object
writeonly
Sets the attribute singleton_resource.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Resource
constructor
A new instance of Resource.
-
#to_hash ⇒ Object
(also: #to_h)
Attributes used for serialization.
Constructor Details
#initialize(attributes = {}) ⇒ Resource
Returns a new instance of Resource.
34 35 36 37 38 |
# File 'lib/delighted/resource.rb', line 34 def initialize(attributes = {}) @id = attributes[:id] define_id_reader if @id build_from_attributes(attributes) end |
Class Attribute Details
.expandable_attributes ⇒ Object
7 8 9 |
# File 'lib/delighted/resource.rb', line 7 def @expandable_attributes ||= {} end |
.path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/delighted/resource.rb', line 4 def path @path end |
.singleton_resource=(value) ⇒ Object (writeonly)
Sets the attribute singleton_resource
5 6 7 |
# File 'lib/delighted/resource.rb', line 5 def singleton_resource=(value) @singleton_resource = value end |
Class Method Details
.identifier_string(identifier_hash) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/delighted/resource.rb', line 15 def identifier_string(identifier_hash) raise ArgumentError, "must pass Hash" unless Hash === identifier_hash raise ArgumentError, "must pass exactly one identifier name and value" unless identifier_hash.size == 1 identifier_key = identifier_hash.keys.first identifier_value = identifier_hash.values.first if identifier_key.to_s == "id" identifier_value.to_s else "#{identifier_key}:#{identifier_value}" end end |
.singleton_resource? ⇒ Boolean
11 12 13 |
# File 'lib/delighted/resource.rb', line 11 def singleton_resource? !!@singleton_resource end |
Instance Method Details
#to_hash ⇒ Object Also known as: to_h
Attributes used for serialization
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/delighted/resource.rb', line 41 def to_hash serialized_attributes = attributes.dup self.class..each_pair.select do |attribute_name, | if === attributes[attribute_name] serialized_attributes[attribute_name] = serialized_attributes[attribute_name].id end end serialized_attributes end |