Class: Microscope::Scope
- Inherits:
-
Struct
- Object
- Struct
- Microscope::Scope
- 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
Defined Under Namespace
Classes: BooleanScope, DateScope, DatetimeScope
Instance Attribute Summary collapse
-
#field ⇒ Object
Returns the value of attribute field.
-
#model ⇒ Object
Returns the value of attribute model.
Class Method Summary collapse
-
.inject_scopes(model, fields, options = {}) ⇒ Object
Inject ActiveRecord scopes into a model.
Instance Method Summary collapse
- #cropped_field ⇒ Object
-
#initialize(*args) ⇒ Scope
constructor
A new instance of Scope.
- #quoted_field ⇒ Object
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
#field ⇒ Object
Returns the value of attribute field
2 3 4 |
# File 'lib/microscope/scope.rb', line 2 def field @field end |
#model ⇒ Object
Returns the value of attribute 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, = {}) 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_field ⇒ Object
14 15 16 |
# File 'lib/microscope/scope.rb', line 14 def cropped_field @cropped_field ||= @field_name.gsub(@cropped_field_regex, '') end |
#quoted_field ⇒ Object
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 |