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

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#servicesObject (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_flagsObject



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



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

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

#get_bindingObject



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

def get_binding
  binding
end

#secrets(secret_name) ⇒ Object



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

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_hashObject



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

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

#to_yamlObject



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

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