Module: SmoothOperator::ORM::ClassMethods

Defined in:
lib/smooth_operator/orm.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#model_nameObject



40
41
42
# File 'lib/smooth_operator/orm.rb', line 40

def model_name
  @model_name ||= name.split('::').last.underscore.capitalize
end

#save_attr_black_listObject



14
15
16
# File 'lib/smooth_operator/orm.rb', line 14

def save_attr_black_list
  @save_attr_black_list ||= [:id, :created_at, :updated_at]
end

#save_attr_white_listObject



19
20
21
# File 'lib/smooth_operator/orm.rb', line 19

def save_attr_white_list
  @save_attr_white_list ||= []
end

#table_nameObject



49
50
51
# File 'lib/smooth_operator/orm.rb', line 49

def table_name
  @table_name ||= model_name_downcase.to_s.pluralize
end

Instance Method Details

#find(id, options = {}) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/smooth_operator/orm.rb', line 23

def find(id, options = {})
  if id == :all
    find_each(options)
  else
    find_one(id, options)
  end
end

#model_name_downcaseObject



44
45
46
# File 'lib/smooth_operator/orm.rb', line 44

def model_name_downcase
  model_name.downcase
end

#safe_find(id, options = {}) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/smooth_operator/orm.rb', line 31

def safe_find(id, options = {})
  begin
    find(id, options)
  rescue Exception => exception #exception.response contains the server response
    id == :all ? [] : nil
  end
end