class Spigot::Proxy
Attributes
Proxy
Spigot::Proxy
provides accessor methods used by the implementation that could be useful for development or custom behavior
Usage:
User.spigot.find_or_create(data)
User.spigot(:twitter).find_or_create(data)
Proxy
Spigot::Proxy
provides accessor methods used by the implementation that could be useful for development or custom behavior
Usage:
User.spigot.find_or_create(data)
User.spigot(:twitter).find_or_create(data)
Public Class Methods
#initialize(resource)
Method to initialize a proxy.
@param service [String] This is the service that dictates the proxy. @param resource [Object] This is the class implementing the proxy.
# File lib/spigot/proxy.rb, line 21 def initialize(resource, service = nil) @service = service @resource = resource end
Public Instance Methods
create
Alias for create_by_api
# File lib/spigot/proxy.rb, line 40 def create(params = {}) resource.create_by_api service_scoped(params) end
create_or_update
Alias for create_or_update_by_api
# File lib/spigot/proxy.rb, line 58 def create_or_update(params = {}) resource.create_or_update_by_api service_scoped(params) end
find
Alias for find_by_api
# File lib/spigot/proxy.rb, line 28 def find(params = {}) resource.find_by_api service_scoped(params) end
find_all
Alias for find_all_by_api
# File lib/spigot/proxy.rb, line 34 def find_all(params = {}) resource.find_all_by_api service_scoped(params) end
find_or_create
Alias for find_or_create_by_api
# File lib/spigot/proxy.rb, line 52 def find_or_create(params = {}) resource.find_or_create_by_api service_scoped(params) end
#map
Return a hash of the data map the current translator is using
# File lib/spigot/proxy.rb, line 70 def map translator.resource_map end
#options
Return a hash of any service specific options for this translator. `Spigot.config` not included
# File lib/spigot/proxy.rb, line 82 def options translator.options || {} end
#present?
Returns a boolean if the current spigot map has a mapping for the current resource
# File lib/spigot/proxy.rb, line 76 def present? translator.resource_map?(resource) end
#translator
Instantiate a Spigot::Translator
object with the contextual service and resource
# File lib/spigot/proxy.rb, line 64 def translator Translator.new(resource, service) end
update
Alias for update_by_api
# File lib/spigot/proxy.rb, line 46 def update(params = {}) resource.update_by_api service_scoped(params) end
Private Instance Methods
# File lib/spigot/proxy.rb, line 88 def service_scoped(params = {}) return params if @service.nil? return { @service => params } if Spigot.config.map.nil? key, data = Spigot::Map::Service.extract(params) return { @service => params } if key.nil? if key.to_sym != @service.to_sym raise Spigot::InvalidServiceError, 'You cannot specify two services' end { key => data } end