Class: KNSEmailEndpoint::Storage::AbstractStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/kns_email_endpoint/storage/abstract_storage.rb

Direct Known Subclasses

FileStorage, MemcacheStorage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ AbstractStorage

Returns a new instance of AbstractStorage.



6
7
8
9
# File 'lib/kns_email_endpoint/storage/abstract_storage.rb', line 6

def initialize(*args)

  reset_storage
end

Instance Attribute Details

#message_idObject (readonly)

Returns the value of attribute message_id.



4
5
6
# File 'lib/kns_email_endpoint/storage/abstract_storage.rb', line 4

def message_id
  @message_id
end

#retry_countObject

Returns the value of attribute retry_count.



4
5
6
# File 'lib/kns_email_endpoint/storage/abstract_storage.rb', line 4

def retry_count
  @retry_count
end

#stateObject

Returns the value of attribute state.



4
5
6
# File 'lib/kns_email_endpoint/storage/abstract_storage.rb', line 4

def state
  @state
end

#unique_idObject (readonly)

Returns the value of attribute unique_id.



4
5
6
# File 'lib/kns_email_endpoint/storage/abstract_storage.rb', line 4

def unique_id
  @unique_id
end

Instance Method Details

#create(opts = {}) ⇒ Object

create should call set_vars and save! if successful and return true otherwise, it should raise an exception



20
21
22
23
# File 'lib/kns_email_endpoint/storage/abstract_storage.rb', line 20

def create(opts={})
  return false #override me

end

#deleteObject

delete should return either true if successful, or false if unsuccessful delete should also call reset_storage if successful



13
14
15
16
# File 'lib/kns_email_endpoint/storage/abstract_storage.rb', line 13

def delete
  return false # override me

end

#find(unique_id) ⇒ Object

find should return self if a record is found after calling set_vars it should return nil if not found and call reset_storage



27
28
29
# File 'lib/kns_email_endpoint/storage/abstract_storage.rb', line 27

def find(unique_id)
  return nil #override me
end

#find_or_create(opts = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/kns_email_endpoint/storage/abstract_storage.rb', line 53

def find_or_create(opts={})
  unless opts[:unique_id] && opts[:message_id]
    raise "Must provide at least a unique_id and message_id"
  end

  s = find(opts[:unique_id])
  return s if s

  return create(opts) ? self : nil
end

#to_hObject



43
44
45
46
47
48
49
50
51
# File 'lib/kns_email_endpoint/storage/abstract_storage.rb', line 43

def to_h
  return {} unless @unique_id
  return {
    :unique_id => @unique_id,
    :message_id => @message_id,
    :retry_count => @retry_count,
    :state => @state
  }
end