lib/lazy_resource/relation.rb in lazy_resource-0.4.0 vs lib/lazy_resource/relation.rb in lazy_resource-0.5.0
- old
+ new
@@ -6,16 +6,21 @@
def resource_queue
Thread.current[:resource_queue] ||= ResourceQueue.new
end
end
- attr_accessor :fetched, :klass, :values, :from, :site, :other_attributes
+ attr_accessor :fetched, :klass, :values, :from, :site, :other_attributes, :request_error
+ attr_writer :method
+ attr_reader :route
def initialize(klass, options = {})
@klass = klass
+ @route = options.fetch(:where_values, {}).delete(:_route)
@values = options.slice(:where_values, :order_value, :limit_value, :offset_value, :page_value)
@fetched = options[:fetched] || false
+ @method = options[:method]
+
unless fetched?
resource_queue.queue(self)
end
self
@@ -27,10 +32,14 @@
def collection_name
from
end
+ def method
+ @method ? @method.downcase.to_sym : nil
+ end
+
def to_params
params = {}
params.merge!(where_values) unless where_values.nil?
params.merge!(:order => order_value) unless order_value.nil?
params.merge!(:limit => limit_value) unless limit_value.nil?
@@ -115,9 +124,10 @@
@fetched
end
def to_a
resource_queue.run if !fetched?
+ raise self.request_error if self.request_error.present?
result
end
def result
@result ||= []