lib/microscope/scope.rb in microscope-1.0.0 vs lib/microscope/scope.rb in microscope-1.0.1
- old
+ new
@@ -1,19 +1,19 @@
module Microscope
- class Scope < Struct.new(:model, :field)
- def initialize(*args)
- super
+ class Scope
+ attr_reader :model, :field
- @field_name = field.name
- @table_name = model.name.tableize
+ def initialize(model, field)
+ @model = model
+ @field = field
end
def quoted_field
- @quoted_field ||= "#{ActiveRecord::Base.connection.quote_table_name(@table_name)}.#{ActiveRecord::Base.connection.quote_column_name(@field_name)}"
+ @quoted_field ||= "#{ActiveRecord::Base.connection.quote_table_name(@model.table_name)}.#{ActiveRecord::Base.connection.quote_column_name(@field.name)}"
end
def cropped_field
- @cropped_field ||= @field_name.gsub(@cropped_field_regex, '')
+ @cropped_field ||= @field.name.gsub(@cropped_field_regex, '')
end
# Inject ActiveRecord scopes into a model
def self.inject_scopes(model, fields, _options)
fields.each do |field|