Class: Scoping::ScopeComposer
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Scoping::ScopeComposer
- Defined in:
- lib/scoping/scope_composer.rb
Instance Method Summary collapse
-
#all ⇒ ActiveRecord::Relation
Apply the scopes and return all the matching records.
-
#count ⇒ Fixnum
Apply the scopes and return count.
-
#decorate ⇒ ActiveRecord::Relation
Apply the scopes and return decorated the matching records.
-
#initialize(base_scope, table = nil) ⇒ ScopeComposer
constructor
Initialize new instance with given scope and criteria table.
-
#paginate(*args) ⇒ Array
Apply the scopes and return paginated records.
-
#scope ⇒ ActiveRecord::Relation
Apply the scopes and return the resulting scope.
Constructor Details
#initialize(base_scope, table = nil) ⇒ ScopeComposer
Initialize new instance with given scope and criteria table.
45 46 47 48 49 50 51 |
# File 'lib/scoping/scope_composer.rb', line 45 def initialize(base_scope, table = nil) @base_scope = base_scope @current_scope = base_scope @applied = false super({}) @table = table if table end |
Instance Method Details
#all ⇒ ActiveRecord::Relation
Apply the scopes and return all the matching records.
56 57 58 59 |
# File 'lib/scoping/scope_composer.rb', line 56 def all return @current_scope.all if fields.empty? apply_fields_on_current_scope end |
#count ⇒ Fixnum
Apply the scopes and return count.
79 80 81 82 |
# File 'lib/scoping/scope_composer.rb', line 79 def count apply_fields_on_current_scope @current_scope.count end |
#decorate ⇒ ActiveRecord::Relation
Apply the scopes and return decorated the matching records.
64 65 66 |
# File 'lib/scoping/scope_composer.rb', line 64 def decorate all.decorate end |
#paginate(*args) ⇒ Array
Apply the scopes and return paginated records.
71 72 73 74 |
# File 'lib/scoping/scope_composer.rb', line 71 def paginate(*args) apply_fields_on_current_scope @current_scope.paginate(*args) end |
#scope ⇒ ActiveRecord::Relation
Apply the scopes and return the resulting scope.
87 88 89 90 |
# File 'lib/scoping/scope_composer.rb', line 87 def scope apply_fields_on_current_scope @current_scope end |