Class: Microscope::Scope

Inherits:
Struct
  • 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(*args) ⇒ Scope

Returns a new instance of Scope.



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

def initialize(*args)
  super

  @field_name = field.name
  @table_name = model.name.tableize
end

Instance Attribute Details

#fieldObject

Returns the value of attribute field

Returns:

  • (Object)

    the current value of field



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

def field
  @field
end

#modelObject

Returns the value of attribute model

Returns:

  • (Object)

    the current value of model



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

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(@table_name)}.#{ActiveRecord::Base.connection.quote_column_name(@field_name)}"
end