Class: Her::Model::OrmAdapter

Inherits:
OrmAdapter::Base
  • Object
show all
Defined in:
lib/her_extension/her_orm_adapter.rb

Instance Method Summary collapse

Instance Method Details

#column_namesObject

get a list of column names for a given class



17
18
19
# File 'lib/her_extension/her_orm_adapter.rb', line 17

def column_names
  @columns ||= klass.instance_methods.grep(/_will_change!$/).map { |e| e.to_s.gsub('_will_change!','') }
end

#create!(attributes = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#create!


44
45
46
# File 'lib/her_extension/her_orm_adapter.rb', line 44

def create!(attributes = {})
  klass.create!(attributes)
end

#destroy(object) ⇒ Object

See Also:

  • OrmAdapter::Base#destroy


49
50
51
# File 'lib/her_extension/her_orm_adapter.rb', line 49

def destroy(object)
  object.destroy if valid_object?(object)
end

#find_all(options = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#find_all


39
40
41
# File 'lib/her_extension/her_orm_adapter.rb', line 39

def find_all(options = {})
  klass.where(options)
end

#find_first(options = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#find_first


34
35
36
# File 'lib/her_extension/her_orm_adapter.rb', line 34

def find_first(options = {})
  klass.where(options).limit(1).first
end

#get(id) ⇒ Object

See Also:

  • OrmAdapter::Base#get


29
30
31
# File 'lib/her_extension/her_orm_adapter.rb', line 29

def get(id)
  klass.find(wrap_key(id))
end

#get!(id) ⇒ Object

Raises:

See Also:

  • OrmAdapter::Base#get!


22
23
24
25
26
# File 'lib/her_extension/her_orm_adapter.rb', line 22

def get!(id)
  res = klass.find(wrap_key(id))
  raise Her::Errors::ResourceNotFound, "resource not found" unless res
  res
end