module Repositorish
Simple Repository(ish) solution to hold query and command logic into self contained objects
# Example:
“‘ruby class UserRepository
include Repositorish repositorish :user, scope: :all def confirmed where.not(confirmed_at: nil) end
end
UserRepository.confirmed # => <User::ActiveRecord_Relation …> “‘
Constants
- CHAINABLE_NAMESPACES
- CHAINABLE_NAMESPACES_REGEX
- VERSION
Attributes
domain[R]
Public Class Methods
included(base)
click to toggle source
# File lib/repositorish.rb, line 27 def self.included(base) base.send :extend, ClassMethods end
new(domain)
click to toggle source
# File lib/repositorish.rb, line 31 def initialize(domain) @domain = domain end
Public Instance Methods
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/repositorish.rb, line 35 def method_missing(method, *args, &block) return super unless domain.respond_to?(method) result = domain.public_send(method, *args, &block) return result unless chainable?(result) @domain = result self end
to_ary()
click to toggle source
# File lib/repositorish.rb, line 45 def to_ary @domain.to_ary end
Private Instance Methods
arel_table()
click to toggle source
# File lib/repositorish.rb, line 53 def arel_table domain.arel_table end
chainable?(domain)
click to toggle source
# File lib/repositorish.rb, line 57 def chainable?(domain) return true if CHAINABLE_NAMESPACES_REGEX =~ domain.class.to_s domain.class == @domain.class end
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
# File lib/repositorish.rb, line 63 def respond_to_missing?(method_name, include_private = false) domain.respond_to?(method_name) || super end