Module: SmoothOperator::ORM
- Included in:
- Base
- Defined in:
- lib/smooth_operator/orm.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #destroy ⇒ Object
- #hash_of_safe_content ⇒ Object
- #invalid? ⇒ Boolean
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
- #save ⇒ Object
- #save! ⇒ Object
- #to_partial_path ⇒ Object
- #valid? ⇒ Boolean
Class Method Details
.included(base) ⇒ Object
6 7 8 9 |
# File 'lib/smooth_operator/orm.rb', line 6 def self.included(base) base.extend(ClassMethods) base.send(:attr_reader, :last_response) end |
Instance Method Details
#destroy ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/smooth_operator/orm.rb', line 96 def destroy return true if new_record? @last_response = self.class.delete(self.id) import_response_errors(@last_response) self.class.successful_response?(@last_response) end |
#hash_of_safe_content ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/smooth_operator/orm.rb', line 125 def hash_of_safe_content safe_hash = hash_of_full_content.dup if self.class.save_attr_white_list.present? safe_hash.slice!(*self.class.save_attr_white_list) else self.class.save_attr_black_list.each { |attribute| safe_hash.delete(attribute) } end safe_hash end |
#invalid? ⇒ Boolean
121 122 123 |
# File 'lib/smooth_operator/orm.rb', line 121 def invalid? !valid? end |
#new_record? ⇒ Boolean
104 105 106 |
# File 'lib/smooth_operator/orm.rb', line 104 def new_record? !persisted? end |
#persisted? ⇒ Boolean
108 109 110 |
# File 'lib/smooth_operator/orm.rb', line 108 def persisted? try(:id).present? end |
#save ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/smooth_operator/orm.rb', line 81 def save begin save! rescue Exception => exception false end end |
#save! ⇒ Object
89 90 91 92 93 94 |
# File 'lib/smooth_operator/orm.rb', line 89 def save! @last_response = create_or_update import_response_errors(@last_response) SmoothOperator::Exceptions.raise_proper_exception(@last_response) unless self.class.successful_response?(@last_response) true end |
#to_partial_path ⇒ Object
112 113 114 115 |
# File 'lib/smooth_operator/orm.rb', line 112 def to_partial_path class_name_plural = self.class.table_name "#{class_name_plural}/#{class_name_plural.singularize}" end |
#valid? ⇒ Boolean
117 118 119 |
# File 'lib/smooth_operator/orm.rb', line 117 def valid? errors.blank? end |