Module: SmoothOperator::Persistence

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

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#extra_paramsObject

Returns the value of attribute extra_params.



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

def extra_params
  @extra_params
end

#meta_dataObject

Returns the value of attribute meta_data.



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

def 
  
end

#reloadedObject

Returns the value of attribute reloaded.



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

def reloaded
  @reloaded
end

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



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/smooth_operator/persistence.rb', line 73

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

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

  success = {}

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

    @destroyed = true if success
  end

  success
end

#destroyed?Boolean



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

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

  @destroyed = false
end

#new_record?Boolean



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

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

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

#persisted?Boolean



61
62
63
# File 'lib/smooth_operator/persistence.rb', line 61

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

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



32
33
34
35
36
37
38
39
40
41
# File 'lib/smooth_operator/persistence.rb', line 32

def reload(relative_path = nil, data = {}, options = {})
  relative_path = id.to_s if Helpers.blank?(relative_path)
  success = {}

  make_remote_call(:get, relative_path, data, options) do |remote_call|
    success = remote_call.status
  end

  success
end

#reloaded?Boolean



55
56
57
58
59
# File 'lib/smooth_operator/persistence.rb', line 55

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

  @reloaded = false
end

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



65
66
67
# File 'lib/smooth_operator/persistence.rb', line 65

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

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



69
70
71
# File 'lib/smooth_operator/persistence.rb', line 69

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