Module: SmoothOperator::Persistence

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

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/smooth_operator/persistence.rb', line 5

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#destroy(relative_path = nil, data = {}, options = {}) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/smooth_operator/persistence.rb', line 54

def destroy(relative_path = nil, data = {}, options = {})
  return false unless persisted?

  relative_path = id.to_s if Helpers.blank?(relative_path)

  success = make_remote_call(self.class.methods_http_verbs[:destroy], relative_path, data, options)

  @destroyed = true if success

  success
end

#destroyed?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
# File 'lib/smooth_operator/persistence.rb', line 36

def destroyed?
  return @destroyed if defined?(@destroyed)

  @destroyed = false
end

#new_record?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/smooth_operator/persistence.rb', line 30

def new_record?
  return @new_record if defined?(@new_record)

  @new_record = Helpers.blank?(get_internal_data("id"))
end

#persisted?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/smooth_operator/persistence.rb', line 42

def persisted?
  !(new_record? || destroyed?)
end

#save(relative_path = nil, data = {}, options = {}) ⇒ Object



46
47
48
# File 'lib/smooth_operator/persistence.rb', line 46

def save(relative_path = nil, data = {}, options = {})
  create_or_update(relative_path, data, options)
end

#save!(relative_path = nil, data = {}, options = {}) ⇒ Object



50
51
52
# File 'lib/smooth_operator/persistence.rb', line 50

def save!(relative_path = nil, data = {}, options = {})
  create_or_update(relative_path, data, options) || raise('RecordNotSaved')
end