Skip to content

Commit

Permalink
reduce some code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
blotto committed Feb 22, 2014
1 parent 51378b8 commit 3932272
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ test/dummy/db/*.sqlite3-journal
test/dummy/log/*.log
test/dummy/tmp/
test/dummy/.sass-cache
*.gem
39 changes: 16 additions & 23 deletions lib/thermometer/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

module Thermometer
module ActiveRecord
module RelationMethods
include Evaluate::Temperatures

private

def sample_records options
options = Thermometer.configuration.process_scope_options(proxy_association.reflection.options[:thermometer].merge(options))
module QueryMethods

def sample options
if options[:limit] && options[:order]
sample = limit(options[:limit]).order(options[:order]).pluck(options[:date])
elsif options[:limit] && options[:order].nil?
Expand All @@ -21,25 +17,22 @@ def sample_records options
end
end


end
=begin
module Temperature
def
rel = if ::ActiveRecord::Relation === self
self
elsif !defined?(::ActiveRecord::Scoping) or ::ActiveRecord::Scoping::ClassMethods.method_defined? :with_scope
# Active Record 3
scoped
else
# Active Record 4
all
end
rel = rel.extending(RelationMethods)

module RelationMethods
include Evaluate::Temperatures
include ActiveRecord::QueryMethods

private

def sample_records options
options = Thermometer.configuration.process_scope_options(proxy_association.reflection.options[:thermometer].merge(options))

sample options
end


end
=end
end

#::ActiveRecord::Base.extend RelationMethods
Expand Down
11 changes: 2 additions & 9 deletions lib/thermometer/temperature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def self.included(base)

module ClassMethods
include Evaluate::Temperatures
include ActiveRecord::QueryMethods

def acts_as_thermometer
include Thermometer::Temperature::InstanceMethods
Expand Down Expand Up @@ -44,15 +45,7 @@ def measures_temperature_for *associations
def sample_records options
options = Thermometer.configuration.process_scope_options(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])
end
sample options
end

end
Expand Down

0 comments on commit 3932272

Please sign in to comment.