Module: Rmodel::RepositoryExt::Scopable
- Included in:
- Rmodel::Repository
- Defined in:
- lib/rmodel/repository_ext/scopable.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #all ⇒ Object
- #delete_all(scope = nil) ⇒ Object
- #destroy_all(scope = nil) ⇒ Object
- #fetch ⇒ Object
- #find_all(scope = nil) ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/rmodel/repository_ext/scopable.rb', line 4 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#all ⇒ Object
29 30 31 |
# File 'lib/rmodel/repository_ext/scopable.rb', line 29 def all fetch.to_a end |
#delete_all(scope = nil) ⇒ Object
20 21 22 23 |
# File 'lib/rmodel/repository_ext/scopable.rb', line 20 def delete_all(scope = nil) raw_query = (scope || fetch).raw_query @source.delete_by_query(raw_query) end |
#destroy_all(scope = nil) ⇒ Object
25 26 27 |
# File 'lib/rmodel/repository_ext/scopable.rb', line 25 def destroy_all(scope = nil) find_all(scope).each { |object| destroy(object) } end |
#fetch ⇒ Object
8 9 10 |
# File 'lib/rmodel/repository_ext/scopable.rb', line 8 def fetch self.class.scope_class.new(self, @source.build_query) end |
#find_all(scope = nil) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/rmodel/repository_ext/scopable.rb', line 12 def find_all(scope = nil) raw_query = (scope || fetch).raw_query @source.exec_query(raw_query).map do |hash| @mapper.deserialize(hash) end end |