Class: FakeSNS::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_sns/database.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database_filename) ⇒ Database

Returns a new instance of Database.



9
10
11
# File 'lib/fake_sns/database.rb', line 9

def initialize(database_filename)
  @database_filename = database_filename || File.join(Dir.home, ".fake_sns.yml")
end

Instance Attribute Details

#database_filenameObject (readonly)

Returns the value of attribute database_filename.



7
8
9
# File 'lib/fake_sns/database.rb', line 7

def database_filename
  @database_filename
end

Instance Method Details

#each_deliverable_messageObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fake_sns/database.rb', line 51

def each_deliverable_message
  topics.each do |topic|
    subscriptions.each do |subscription|
      messages.each do |message|
        if message.topic_arn == topic.arn
          yield subscription, message
        end
      end
    end
  end
end

#messagesObject



27
28
29
# File 'lib/fake_sns/database.rb', line 27

def messages
  @messages ||= MessageCollection.new(store)
end

#perform(action, params) ⇒ Object



13
14
15
16
17
# File 'lib/fake_sns/database.rb', line 13

def perform(action, params)
  action_instance = action_provider(action).new(self, params)
  action_instance.call
  Response.new(action_instance)
end

#replace(data) ⇒ Object



43
44
45
# File 'lib/fake_sns/database.rb', line 43

def replace(data)
  store.replace(data)
end

#resetObject



31
32
33
34
35
# File 'lib/fake_sns/database.rb', line 31

def reset
  topics.reset
  subscriptions.reset
  messages.reset
end

#subscriptionsObject



23
24
25
# File 'lib/fake_sns/database.rb', line 23

def subscriptions
  @subscriptions ||= SubscriptionCollection.new(store)
end

#to_yamlObject



47
48
49
# File 'lib/fake_sns/database.rb', line 47

def to_yaml
  store.to_yaml
end

#topicsObject



19
20
21
# File 'lib/fake_sns/database.rb', line 19

def topics
  @topics ||= TopicCollection.new(store)
end

#transactionObject



37
38
39
40
41
# File 'lib/fake_sns/database.rb', line 37

def transaction
  store.transaction do
    yield
  end
end