Module: SmoothOperator::Operator::ORM

Included in:
Base
Defined in:
lib/smooth_operator/operator/orm.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
# File 'lib/smooth_operator/operator/orm.rb', line 6

def self.included(base)
  base.extend(ClassMethods)
  base.send(:attr_reader, :last_response)
  base.send(:attr_reader, :exception)
end

Instance Method Details

#destroy(options = {}) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/smooth_operator/operator/orm.rb', line 79

def destroy(options = {})
  return true if new_record?
  
  http_handler_orm.make_the_call(:delete, options, id) do |remote_call|
    after_create_update_or_destroy(remote_call)
  end
end

#save(options = {}) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/smooth_operator/operator/orm.rb', line 60

def save(options = {})
  begin
    save!(options)
  rescue Exception => exception
    send("exception=", exception)
    false
  end
end

#save!(options = {}) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/smooth_operator/operator/orm.rb', line 69

def save!(options = {})
  options = build_options_for_save(options)

  if new_record?
    http_handler_orm.make_the_call(:post, options, '') { |remote_call| after_create_update_or_destroy(remote_call) }
  else
    http_handler_orm.make_the_call(:put, options, id) { |remote_call| after_create_update_or_destroy(remote_call) }
  end
end