Module: Datapathy::Model::Crud::ClassMethods

Defined in:
lib/datapathy/model/crud.rb

Instance Method Summary collapse

Instance Method Details

#[](value) ⇒ Object



32
33
34
# File 'lib/datapathy/model/crud.rb', line 32

def [](value)
  detect{ |m| m.key == value} || raise(Datapathy::RecordNotFound, "No #{model} found with #{key} `#{value}`")
end

#create(*attributes) ⇒ Object



28
29
30
# File 'lib/datapathy/model/crud.rb', line 28

def create(*attributes)
  collection = Datapathy::Collection.new(self, *attributes).create
end

#delete(&blk) ⇒ Object



53
54
55
# File 'lib/datapathy/model/crud.rb', line 53

def delete(&blk)
  select(&blk).delete
end

#detect(*attrs, &blk) ⇒ Object Also known as: first, find



43
44
45
# File 'lib/datapathy/model/crud.rb', line 43

def detect(*attrs, &blk)
  select(*attrs, &blk).first
end

#select(*attrs, &blk) ⇒ Object Also known as: all, find_all



36
37
38
39
# File 'lib/datapathy/model/crud.rb', line 36

def select(*attrs, &blk)
  query = Datapathy::Query.new(model)
  Datapathy::Collection.new(query).select(*attrs, &blk)
end

#update(attributes, &blk) ⇒ Object



49
50
51
# File 'lib/datapathy/model/crud.rb', line 49

def update(attributes, &blk)
  select(&blk).update(attributes)
end