class JsonApiResource::Resource
Attributes
cache_expires_in[RW]
client[RW]
Public Class Methods
new(opts={})
click to toggle source
# File lib/json_api_resource/resource.rb, line 35 def initialize(opts={}) raise_unless client_class.present?, "A resource must have a client class", JsonApiResource::Errors::JsonApiResourceError self.attributes = opts self.errors = ActiveModel::Errors.new(self) self.populate_missing_fields end
Protected Class Methods
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/json_api_resource/resource.rb, line 75 def self.method_missing(method, *args, &block) if match = method.to_s.match(/^(.*)=$/) self.client_class.send(match[0], args.first) elsif self.client_class.respond_to?(method.to_sym) results = request(method, *args).data if results.is_a? JsonApiClient::ResultSet results.map! do |result| self.new(:client => result) end end results else super end rescue Multiconnect::Error::UnsuccessfulRequest => e handle_failed_request e end
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
# File lib/json_api_resource/resource.rb, line 100 def self.respond_to_missing?(method_name, include_private = false) client_class.respond_to?(method_name.to_sym) || super end
Public Instance Methods
attributes=(attr = {})
click to toggle source
# File lib/json_api_resource/resource.rb, line 51 def attributes=(attr = {}) client_params = attr.delete(:client) if attr.is_a? self.client_class self.client = attr elsif client_params self.client = client_params else self.client ||= self.client_class.new(self.schema) self.client.attributes = attr end end
new_record?()
click to toggle source
# File lib/json_api_resource/resource.rb, line 43 def new_record? self.id.nil? end
persisted?()
click to toggle source
# File lib/json_api_resource/resource.rb, line 47 def persisted? !new_record? end
Protected Instance Methods
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/json_api_resource/resource.rb, line 65 def method_missing(method, *args, &block) if match = method.to_s.match(/^(.*=)$/) self.client.send(match[0], args.first) elsif self.client.respond_to?(method.to_sym) connection.execute( method, *args ).data else super end end
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
# File lib/json_api_resource/resource.rb, line 96 def respond_to_missing?(method_name, include_private = false) client.respond_to?(method_name.to_sym) || super end