Class: Shippy::Compose

Inherits:
Object
  • Object
show all
Defined in:
lib/shippy/compose.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Compose

Returns a new instance of Compose.



5
6
7
8
9
# File 'lib/shippy/compose.rb', line 5

def initialize(name, &block)
  @name = name
  @services = []
  instance_eval(&block)
end

Instance Attribute Details

#name ⇒ Object (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/shippy/compose.rb', line 3

def name
  @name
end

#services ⇒ Object (readonly)

Returns the value of attribute services.



3
4
5
# File 'lib/shippy/compose.rb', line 3

def services
  @services
end

Instance Method Details

#deploy_flags ⇒ Object



20
21
22
23
24
25
26
# File 'lib/shippy/compose.rb', line 20

def deploy_flags
  if block_given?
    @deploy_flags = yield
  else
    @deploy_flags
  end
end

#each_hook(&block) ⇒ Object



40
41
42
43
44
# File 'lib/shippy/compose.rb', line 40

def each_hook(&block)
  @services
    .flat_map(&:hooks)
    .each(&block)
end

#get_binding ⇒ Object



50
51
52
# File 'lib/shippy/compose.rb', line 50

def get_binding
  binding
end

#secrets(secret_name) ⇒ Object



46
47
48
# File 'lib/shippy/compose.rb', line 46

def secrets(secret_name)
  Shippy.x.secrets(name, secret_name)
end

#service(name, &block) ⇒ Object



11
12
13
14
# File 'lib/shippy/compose.rb', line 11

def service(name, &block)
  service = Service.new(name, app: self, &block)
  @services << service
end

#to_hash ⇒ Object



28
29
30
31
32
33
34
# File 'lib/shippy/compose.rb', line 28

def to_hash
  data = {}
  data[:services] = services.map(&:to_hash).reduce(:merge)
  data[:volumes] = volumes_hash.presence
  data[:networks] = networks_hash.presence
  data.compact
end

#to_yaml ⇒ Object



36
37
38
# File 'lib/shippy/compose.rb', line 36

def to_yaml
  to_hash.deep_stringify_keys.to_yaml
end

#xservice(name, &block) ⇒ Object



16
17
18
# File 'lib/shippy/compose.rb', line 16

def xservice(name, &block)
  puts "Service #{name} is disabled"
end