Class: ZendeskRails::Resource
- Inherits:
-
Object
- Object
- ZendeskRails::Resource
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations
- Defined in:
- app/models/zendesk_rails/resource.rb
Defined Under Namespace
Classes: NotFoundException
Class Attribute Summary collapse
-
.known_fields ⇒ Object
readonly
Returns the value of attribute known_fields.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Resource
constructor
A new instance of Resource.
- #method_missing(meth, *args, &block) ⇒ Object
- #persisted? ⇒ Boolean
- #respond_to_missing?(meth) ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Resource
Returns a new instance of Resource.
38 39 40 |
# File 'app/models/zendesk_rails/resource.rb', line 38 def initialize(attributes = {}) @attributes = attributes.with_indifferent_access end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'app/models/zendesk_rails/resource.rb', line 50 def method_missing(meth, *args, &block) if attributes.key?(meth) attributes[meth] elsif known_fields.include?(meth.to_s) nil else super end end |
Class Attribute Details
.known_fields ⇒ Object (readonly)
Returns the value of attribute known_fields.
23 24 25 |
# File 'app/models/zendesk_rails/resource.rb', line 23 def known_fields @known_fields end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
36 37 38 |
# File 'app/models/zendesk_rails/resource.rb', line 36 def attributes @attributes end |
Class Method Details
.has_fields(*names) ⇒ Object
25 26 27 28 |
# File 'app/models/zendesk_rails/resource.rb', line 25 def has_fields(*names) @known_fields ||= [] @known_fields |= names.map(&:to_s) end |
.resource_not_found!(id) ⇒ Object
30 31 32 |
# File 'app/models/zendesk_rails/resource.rb', line 30 def resource_not_found!(id) fail NotFoundException.new(id, self) end |
Instance Method Details
#persisted? ⇒ Boolean
42 43 44 |
# File 'app/models/zendesk_rails/resource.rb', line 42 def persisted? false end |
#respond_to_missing?(meth) ⇒ Boolean
46 47 48 |
# File 'app/models/zendesk_rails/resource.rb', line 46 def respond_to_missing?(meth, *) known_fields.include?(meth.to_s) || super end |