Module: SmoothOperator::Core

Included in:
Base
Defined in:
lib/smooth_operator/core.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#as_json(options = nil) ⇒ Object



8
9
10
# File 'lib/smooth_operator/core.rb', line 8

def as_json(options = nil)
  @table.as_json(options)
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

Returns:

  • (Boolean)


29
30
31
# File 'lib/smooth_operator/core.rb', line 29

def invalid?
  !valid?
end

#new_record?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/smooth_operator/core.rb', line 12

def new_record?
  !persisted?
end

#persisted?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/smooth_operator/core.rb', line 16

def persisted?
  try(:id).present?
end

#safe_table_hashObject



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_hashObject



4
5
6
# File 'lib/smooth_operator/core.rb', line 4

def table_hash
  @table
end

#to_partial_pathObject



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

Returns:

  • (Boolean)


25
26
27
# File 'lib/smooth_operator/core.rb', line 25

def valid?
  errors.blank?
end