class MagLoft::RemoteCollection
Public Class Methods
new(resource_class, filter = {})
click to toggle source
# File lib/magloft/remote_collection.rb, line 3 def initialize(resource_class, filter = {}) @resource_class = resource_class @filter = filter end
Public Instance Methods
all()
click to toggle source
# File lib/magloft/remote_collection.rb, line 24 def all @resource_class.where(@filter) end
create(attributes = {})
click to toggle source
# File lib/magloft/remote_collection.rb, line 44 def create(attributes = {}) entity = @resource_class.new(attributes.merge(@filter)) entity.save entity end
find(id)
click to toggle source
# File lib/magloft/remote_collection.rb, line 12 def find(id) @resource_class.where(@filter.merge(id: id)).first end
find_one(params)
click to toggle source
# File lib/magloft/remote_collection.rb, line 20 def find_one(params) @resource_class.find_one(params.merge(@filter)) end
method_missing(name, *args, &block)
click to toggle source
Calls superclass method
# File lib/magloft/remote_collection.rb, line 28 def method_missing(name, *args, &block) if name[0..7] == "find_by_" and args.length == 1 attribute = name[8..-1].to_sym if @resource_class.remote_attributes.include?(attribute) params = {} params[attribute] = args.first return self.find_one(params.merge(@filter)) end end super end
new(attributes)
click to toggle source
# File lib/magloft/remote_collection.rb, line 8 def new(attributes) @resource_class.new(attributes.merge(@filter)) end
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
# File lib/magloft/remote_collection.rb, line 40 def respond_to_missing?(method_name, include_private = false) method_name.to_s.start_with?('find_by_') || super end
where(params)
click to toggle source
# File lib/magloft/remote_collection.rb, line 16 def where(params) @resource_class.where(params.merge(@filter)) end