Skip to content

Commit

Permalink
simplify conditional logic
Browse files Browse the repository at this point in the history
  • Loading branch information
blotto committed Feb 24, 2014
1 parent c3279ba commit 08c6e52
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions lib/thermometer/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ module ActiveRecord

module QueryMethods

def sample options
def data_sample options

if options[:limit] && options[:order]
sample = limit(options[:limit]).order(options[:order]).pluck(options[:date])
elsif options[:limit] && options[:order].nil?
sample = limit(options[:limit]).pluck(options[:date])
elsif options[:limit].nil? && options[:order]
sample = order(options[:order]).pluck(options[:date])
else
sample = pluck(options[:date])
sample = limit(options[:limit]).order(options[:order])#.pluck(options[:date])
elsif options[:limit] #&& options[:order].nil?
sample = limit(options[:limit])#.pluck(options[:date])
else #options[:order] #options[:limit].nil? &&
sample = order(options[:order])
end

return sample.pluck(options[:date])
end


#def conditions options
# yield options[:limit],options[:order],options[:date]
#end

end

module RelationMethods
Expand All @@ -28,7 +34,7 @@ module RelationMethods
def sample_records options
options = Thermometer.configuration.process_scope_options(proxy_association.reflection.options[:thermometer].merge(options))

sample options
data_sample options
end


Expand Down
2 changes: 1 addition & 1 deletion lib/thermometer/temperature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def measures_temperature_for *associations
def sample_records options
options = Thermometer.configuration.process_scope_options(options)

sample options
data_sample options
end

end
Expand Down

0 comments on commit 08c6e52

Please sign in to comment.