Class: Ambition::Context
- Inherits:
-
Object
- Object
- Ambition::Context
- Defined in:
- lib/ambition/adapters/active_record/context.rb
Instance Method Summary collapse
- #count(*args) ⇒ Object (also: #size)
- #count_destroyed_only(*args) ⇒ Object
- #count_with_destroyed(*args) ⇒ Object
- #find(*args) ⇒ Object
- #find_destroyed_only(*args) ⇒ Object
- #find_with_destroyed(*args) ⇒ Object
- #paginate(*args) ⇒ Object
- #within(outer_scope, join_association = nil) ⇒ Object
Instance Method Details
#count(*args) ⇒ Object Also known as: size
14 15 16 |
# File 'lib/ambition/adapters/active_record/context.rb', line 14 def count *args with_context_scope(to_hash) { owner.count *args } end |
#count_destroyed_only(*args) ⇒ Object
22 23 24 |
# File 'lib/ambition/adapters/active_record/context.rb', line 22 def count_destroyed_only *args with_context_scope(to_hash) { owner.count_destroyed_only *args } end |
#count_with_destroyed(*args) ⇒ Object
19 20 21 |
# File 'lib/ambition/adapters/active_record/context.rb', line 19 def count_with_destroyed *args with_context_scope(to_hash) { owner.count_with_destroyed *args } end |
#find(*args) ⇒ Object
4 5 6 |
# File 'lib/ambition/adapters/active_record/context.rb', line 4 def find *args with_context_scope(to_hash) { owner.find *args } end |
#find_destroyed_only(*args) ⇒ Object
10 11 12 |
# File 'lib/ambition/adapters/active_record/context.rb', line 10 def find_destroyed_only *args with_context_scope(to_hash) { owner.find_destroyed_only *args } end |
#find_with_destroyed(*args) ⇒ Object
7 8 9 |
# File 'lib/ambition/adapters/active_record/context.rb', line 7 def find_with_destroyed *args with_context_scope(to_hash) { owner.find_with_destroyed *args } end |
#paginate(*args) ⇒ Object
26 27 28 |
# File 'lib/ambition/adapters/active_record/context.rb', line 26 def paginate *args with_context_scope(to_hash) { owner.paginate *args } end |
#within(outer_scope, join_association = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ambition/adapters/active_record/context.rb', line 30 def within outer_scope, join_association = nil context = ambition_context unless outer_scope.nil? join_association ||= outer_scope.owner.symbolize raise "#{owner} doesn't have a #{join_association.inspect} association. Make sure it's spelt and pluralized correctly and speficied as a symbol." unless context.owner.reflections.has_key?(join_association) (context.stash[:joins] ||= []).push(join_association).concat(outer_scope.stash[:joins] || []).uniq! context.clauses[:select].concat(outer_scope.clauses[:select]).uniq! end context end |