class Infopark::Crm::Core::Resource
Base class for every resource model
Supports the ActiveResource::Base lifecycle methods, such as
-
Resource.create(attributes)
-
Resource.new(attributes)
-
Resource.find(id)
-
resource.update_attributes(attributes)
-
resource.save
See the {rubydoc.info/gems/activeresource/3.2.8/frames ActiveResource documentation} for a detailed description.
Public Class Methods
configure(configuration)
click to toggle source
@private
# File lib/crm_connector/core/resource.rb, line 73 def self.configure(configuration) self.site = configuration.url + '/api/' if configuration.url self.user = configuration.login self.password = configuration.api_key self.locale = configuration.locale self.http_host = configuration.http_host end
delete(id, options = {})
click to toggle source
@webcrm_todo remove when github.com/rails/rails/issues/2479 is done @private
# File lib/crm_connector/core/resource.rb, line 60 def self.delete(id, options = {}) connection.delete(element_path(id, options), headers) end
deprecated(deprecated, hint = nil)
click to toggle source
@private
# File lib/crm_connector/core/resource.rb, line 41 def self.deprecated(deprecated, hint = nil) return unless @@deprecation_warnings text = "[WebCrmConnector] #{deprecated} is deprecated." text << " #{hint}" if hint if defined?(Rails.logger) Rails.logger.warn(text) else $stderr.puts(text) end end
element_name()
click to toggle source
@private
# File lib/crm_connector/core/resource.rb, line 26 def self.element_name @element_name ||= first_resource_child.model_name.element end
headers()
click to toggle source
@private
Calls superclass method
# File lib/crm_connector/core/resource.rb, line 65 def self.headers headers = super headers.merge!({"Accept-Language" => self.locale}) if self.locale headers.merge!({"Host" => self.http_host}) if self.http_host headers end
inherited(subclass)
click to toggle source
@private
# File lib/crm_connector/core/resource.rb, line 35 def self.inherited(subclass) subclass.schema = schema subclass.format = format end
schema=(definition)
click to toggle source
@private
Calls superclass method
# File lib/crm_connector/core/resource.rb, line 82 def self.schema=(definition) ares_compatible_definition = {} (definition || []).each do |k, v| ares_compatible_definition[k] = SchemaSupport.schema_type(v) end super(ares_compatible_definition) end
Private Class Methods
first_resource_child()
click to toggle source
# File lib/crm_connector/core/resource.rb, line 143 def self.first_resource_child ancestors.each_cons(2) do |child, parent| return child if (parent == Infopark::Crm::Core::Resource) end end
Public Instance Methods
errors()
click to toggle source
Support for field associatable errors (without humanized name guessing) @private
# File lib/crm_connector/core/resource.rb, line 122 def errors @errors ||= Errors.new(self) end
known_attributes()
click to toggle source
@private
Calls superclass method
# File lib/crm_connector/core/resource.rb, line 53 def known_attributes Core::KnownAttributes.new(super) end