class Ohm::Scope
Constants
- VERSION
Attributes
dict[R]
model[R]
Public Class Methods
new(model, dict)
click to toggle source
# File lib/ohm/scope.rb, line 5 def initialize(model, dict) @model, @dict = model, dict end
Public Instance Methods
[](id)
click to toggle source
# File lib/ohm/scope.rb, line 17 def [](id) all[id] end
all()
click to toggle source
# File lib/ohm/scope.rb, line 39 def all find({}) end
build(klass = model, **attributes)
click to toggle source
# File lib/ohm/scope.rb, line 13 def build(klass = model, **attributes) klass.new(scoped(attributes)) end
create(**attributes)
click to toggle source
# File lib/ohm/scope.rb, line 9 def create(**attributes) build(**attributes).save end
exists?(id)
click to toggle source
# File lib/ohm/scope.rb, line 35 def exists?(id) !!all[id] end
fetch(ids)
click to toggle source
# File lib/ohm/scope.rb, line 21 def fetch(ids) all.fetch(ids.select { |id| exists?(id) }) end
find(attributes)
click to toggle source
# File lib/ohm/scope.rb, line 43 def find(attributes) model.find(scoped(attributes)) end
with(key, val)
click to toggle source
# File lib/ohm/scope.rb, line 25 def with(key, val) instance = model.with(key, val) if instance && exists?(instance.id) instance else nil end end
Protected Instance Methods
scoped(attributes = {})
click to toggle source
# File lib/ohm/scope.rb, line 51 def scoped(attributes = {}) attributes.merge(dict) end