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



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

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

  relative_path = "#{id}" 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
# File 'lib/smooth_operator/persistence.rb', line 36

def destroyed?
  @destroyed || false
end

#last_remote_callObject



40
41
42
# File 'lib/smooth_operator/persistence.rb', line 40

def last_remote_call
  @last_remote_call
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)


44
45
46
# File 'lib/smooth_operator/persistence.rb', line 44

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

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



48
49
50
# File 'lib/smooth_operator/persistence.rb', line 48

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

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



52
53
54
# File 'lib/smooth_operator/persistence.rb', line 52

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