Module: SmoothOperator::Core
- Included in:
- Base
- Defined in:
- lib/smooth_operator/core.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
- #assign_attributes(attributes = {}) ⇒ Object
- #invalid? ⇒ Boolean
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
- #safe_table_hash ⇒ Object
- #table_hash ⇒ Object
- #to_partial_path ⇒ Object
- #valid? ⇒ Boolean
Instance Method Details
#as_json(options = nil) ⇒ Object
8 9 10 |
# File 'lib/smooth_operator/core.rb', line 8 def as_json( = nil) @table.as_json() end |
#assign_attributes(attributes = {}) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/smooth_operator/core.rb', line 33 def assign_attributes(attributes = {}) return if attributes.blank? attributes.each do |name, value| send("#{name}=", value) end end |
#invalid? ⇒ Boolean
29 30 31 |
# File 'lib/smooth_operator/core.rb', line 29 def invalid? !valid? end |
#new_record? ⇒ Boolean
12 13 14 |
# File 'lib/smooth_operator/core.rb', line 12 def new_record? !persisted? end |
#persisted? ⇒ Boolean
16 17 18 |
# File 'lib/smooth_operator/core.rb', line 16 def persisted? try(:id).present? end |
#safe_table_hash ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/smooth_operator/core.rb', line 41 def safe_table_hash safe_hash = table_hash.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 |
#table_hash ⇒ Object
4 5 6 |
# File 'lib/smooth_operator/core.rb', line 4 def table_hash @table end |
#to_partial_path ⇒ Object
20 21 22 23 |
# File 'lib/smooth_operator/core.rb', line 20 def to_partial_path class_name_plural = self.class.table_name "#{class_name_plural}/#{class_name_plural.singularize}" end |
#valid? ⇒ Boolean
25 26 27 |
# File 'lib/smooth_operator/core.rb', line 25 def valid? errors.blank? end |