Module: SmoothOperator::ORM::ClassMethods
- Defined in:
- lib/smooth_operator/orm.rb
Instance Attribute Summary collapse
- #model_name ⇒ Object
- #save_attr_black_list ⇒ Object
- #save_attr_white_list ⇒ Object
- #table_name ⇒ Object
Instance Method Summary collapse
- #find(id, options = {}) ⇒ Object
- #model_name_downcase ⇒ Object
- #safe_find(id, options = {}) ⇒ Object
Instance Attribute Details
#model_name ⇒ Object
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_list ⇒ Object
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_list ⇒ Object
19 20 21 |
# File 'lib/smooth_operator/orm.rb', line 19 def save_attr_white_list @save_attr_white_list ||= [] end |
#table_name ⇒ Object
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, = {}) if id == :all find_each() else find_one(id, ) end end |
#model_name_downcase ⇒ Object
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, = {}) begin find(id, ) rescue Exception => exception #exception.response contains the server response id == :all ? [] : nil end end |