Class: CycloneLariat::Migration

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
LunaPark::Extensions::Injector
Defined in:
lib/cyclone_lariat/migration.rb

Constant Summary collapse

DIR =
'./lariat/migrate'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build_graph(presenter: Presenters::Graph) ⇒ Object



150
151
152
# File 'lib/cyclone_lariat/migration.rb', line 150

def build_graph(presenter: Presenters::Graph)
  puts presenter.call(new.subscriptions)
end

.list_queues(presenter: Presenters::Queues) ⇒ Object



142
143
144
# File 'lib/cyclone_lariat/migration.rb', line 142

def list_queues(presenter: Presenters::Queues)
  puts presenter.call(new.queues)
end

.list_subscriptions(presenter: Presenters::Subscriptions) ⇒ Object



146
147
148
# File 'lib/cyclone_lariat/migration.rb', line 146

def list_subscriptions(presenter: Presenters::Subscriptions)
  puts presenter.call(new.subscriptions)
end

.list_topics(presenter: Presenters::Topics) ⇒ Object



138
139
140
# File 'lib/cyclone_lariat/migration.rb', line 138

def list_topics(presenter: Presenters::Topics)
  puts presenter.call(new.topics)
end

.migrate(repo: CycloneLariat::Repo::Versions.new, dir: DIR, service: Services::Migrate) ⇒ Object



130
131
132
# File 'lib/cyclone_lariat/migration.rb', line 130

def migrate(repo: CycloneLariat::Repo::Versions.new, dir: DIR, service: Services::Migrate)
  puts service.new(repo: repo, dir: dir).call
end

.rollback(version = nil, repo: CycloneLariat::Repo::Versions.new, dir: DIR, service: Services::Rollback) ⇒ Object



134
135
136
# File 'lib/cyclone_lariat/migration.rb', line 134

def rollback(version = nil, repo: CycloneLariat::Repo::Versions.new, dir: DIR, service: Services::Rollback)
  puts service.new(repo: repo, dir: dir).call(version)
end

Instance Method Details

#create(resource) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/cyclone_lariat/migration.rb', line 37

def create(resource)
  process(
    resource: resource,
    for_topic: ->(topic) { sns.create(topic) },
    for_queue: ->(queue) { sqs.create(queue) }
  )

  puts "  #{resource.class.name.split('::').last} was created `#{resource.name}`"
end

#default_policy(queue) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/cyclone_lariat/migration.rb', line 80

def default_policy(queue)
  {
    'Sid' => queue.arn,
    'Effect' => 'Allow',
    'Principal' => {
      'AWS' => '*'
    },
    'Action' => 'SQS:*',
    'Resource' => queue.arn,
    'Condition' => {
      'ArnEquals' => {
        'aws:SourceArn' => fanout_arn_pattern
      }
    }
  }
end

#delete(resource) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/cyclone_lariat/migration.rb', line 47

def delete(resource)
  process(
    resource: resource,
    for_topic: ->(topic) { sns.delete(topic) },
    for_queue: ->(queue) { sqs.delete(queue) }
  )
  puts "  #{resource.class.name.split('::').last} was deleted `#{resource.name}`"
end

#downObject

Raises:

  • (LunaPark::Errors::Abstract)


30
31
32
# File 'lib/cyclone_lariat/migration.rb', line 30

def down
  raise LunaPark::Errors::Abstract, "Down method should be defined in #{self.class.name}"
end

#exists?(resource) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
# File 'lib/cyclone_lariat/migration.rb', line 56

def exists?(resource)
  process(
    resource: resource,
    for_topic: ->(topic) { sns.exists?(topic) },
    for_queue: ->(queue) { sqs.exists?(queue) }
  )
end

#queuesObject



101
102
103
# File 'lib/cyclone_lariat/migration.rb', line 101

def queues
  sqs.list_all
end

#subscribe(topic:, endpoint:, policy: nil) ⇒ Object



64
65
66
67
68
69
# File 'lib/cyclone_lariat/migration.rb', line 64

def subscribe(topic:, endpoint:, policy: nil)
  policy ||= default_policy(endpoint)
  sqs.add_policy(queue: endpoint, policy: policy) if endpoint.queue?
  sns.subscribe topic: topic, endpoint: endpoint
  puts "  Subscription was created `#{topic.name} -> #{endpoint.name}`"
end

#subscribed?(topic:, endpoint:) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/cyclone_lariat/migration.rb', line 76

def subscribed?(topic:, endpoint:)
  sns.subscribed?(topic: topic, endpoint: endpoint)
end

#subscriptionsObject



105
106
107
# File 'lib/cyclone_lariat/migration.rb', line 105

def subscriptions
  sns.list_subscriptions
end

#topicsObject



97
98
99
# File 'lib/cyclone_lariat/migration.rb', line 97

def topics
  sns.list_all
end

#unsubscribe(topic:, endpoint:) ⇒ Object



71
72
73
74
# File 'lib/cyclone_lariat/migration.rb', line 71

def unsubscribe(topic:, endpoint:)
  sns.unsubscribe topic: topic, endpoint: endpoint
  puts "  Subscription was deleted `#{topic.name} -> #{endpoint.name}`"
end

#upObject

Raises:

  • (LunaPark::Errors::Abstract)


26
27
28
# File 'lib/cyclone_lariat/migration.rb', line 26

def up
  raise LunaPark::Errors::Abstract, "Up method should be defined in #{self.class.name}"
end