Class: Microscope::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/microscope/scope.rb,
lib/microscope/scope/date_scope.rb,
lib/microscope/scope/boolean_scope.rb,
lib/microscope/scope/datetime_scope.rb

Direct Known Subclasses

BooleanScope, DatetimeScope

Defined Under Namespace

Classes: BooleanScope, DateScope, DatetimeScope

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, field) ⇒ Scope

Returns a new instance of Scope.



5
6
7
8
# File 'lib/microscope/scope.rb', line 5

def initialize(model, field)
  @model = model
  @field = field
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



3
4
5
# File 'lib/microscope/scope.rb', line 3

def field
  @field
end

#modelObject (readonly)

Returns the value of attribute model.



3
4
5
# File 'lib/microscope/scope.rb', line 3

def model
  @model
end

Class Method Details

.inject_scopes(model, fields, _options) ⇒ Object

Inject ActiveRecord scopes into a model



19
20
21
22
23
24
# File 'lib/microscope/scope.rb', line 19

def self.inject_scopes(model, fields, _options)
  fields.each do |field|
    scope = "#{field.type.to_s.camelize}Scope"
    "Microscope::Scope::#{scope}".constantize.new(model, field).apply if const_defined?(scope)
  end
end

Instance Method Details

#cropped_fieldObject



14
15
16
# File 'lib/microscope/scope.rb', line 14

def cropped_field
  @cropped_field ||= @field.name.gsub(@cropped_field_regex, '')
end

#quoted_fieldObject



10
11
12
# File 'lib/microscope/scope.rb', line 10

def quoted_field
  @quoted_field ||= "#{ActiveRecord::Base.connection.quote_table_name(@model.table_name)}.#{ActiveRecord::Base.connection.quote_column_name(@field.name)}"
end