Class: RubyYacht::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_yacht/dsl/configuration.rb

Overview

This class stores the configuration for the system.

For more information on the configuration DSL, see RubyYacht::Configuration::DSL.

Defined Under Namespace

Classes: DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

This initializer creates an empty configuration.



11
12
13
# File 'lib/ruby_yacht/dsl/configuration.rb', line 11

def initialize
  self.clear
end

Instance Attribute Details

#disable_docker_machineObject

Whether we should avoid using docker-machine even if it is installed.

If docker-machine is not installed, the value of this flag will be ignored.



39
40
41
# File 'lib/ruby_yacht/dsl/configuration.rb', line 39

def disable_docker_machine
  @disable_docker_machine
end

#hooksObject

The hooks to customize the build and run processes. Each entry is a RubyYacht::Hook



29
30
31
# File 'lib/ruby_yacht/dsl/configuration.rb', line 29

def hooks
  @hooks
end

#projectsObject

The projects that are part of this system. Each entry is a RubyYacht::Project



25
26
27
# File 'lib/ruby_yacht/dsl/configuration.rb', line 25

def projects
  @projects
end

#server_typesObject

The app types that we can support. Each entry is a Symbol.



33
34
35
# File 'lib/ruby_yacht/dsl/configuration.rb', line 33

def server_types
  @server_types
end

Instance Method Details

#clearObject

This method erases all the configuration.



16
17
18
19
20
21
# File 'lib/ruby_yacht/dsl/configuration.rb', line 16

def clear
  @projects = []
  @hooks = []
  @server_types = []
  @avoid_docker_machine = false
end

#fetch_hooks(server, event_type) ⇒ Object

This method pulls up the hooks that we have defined.

Parameters

  • server: App/Database: The server we are fetching hooks for.
  • event_type: Symbol: The event that we are fetching hooks for.

Returns

The matching hooks. This will be an Array where each item is a Hook.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ruby_yacht/dsl/configuration.rb', line 51

def fetch_hooks(server, event_type)
  case server
  when App
    app_types = [server.server_type,:all]
    database_types = [:all]
    database = server.database
    database_types << database.server_type if database
    web_server_types = [:all] + server.project.web_servers.map(&:server_type).uniq
    container_type = :app
  when Database
    database_types = [server.server_type, :all]
    app_types = [:all]
    app_types += server.apps.map(&:server_type)
    web_server_types = [:all] + server.project.web_servers.map(&:server_type).uniq
    container_type = :database
  when WebServer
    app_types = [:all] + server.project.apps.map(&:server_type).uniq
    database_types = [:all] + server.project.databases.map(&:server_type).uniq
    web_server_types = [:all, server.server_type]
    container_type = :web
  else
    return []
  end
  self.hooks.select do |hook|
    hook.event_type == event_type &&
      app_types.include?(hook.app_server_type) &&
      database_types.include?(hook.database_server_type) &&
      web_server_types.include?(hook.web_server_type) &&
      hook.container_type == container_type
  end
end

#find_server_type(name) ⇒ Object

This method finds an server type by name.

Parameters

  • name: Symbol The name of the server type to return.

Returns

The RubyYacht::ServerType with that name.



92
93
94
# File 'lib/ruby_yacht/dsl/configuration.rb', line 92

def find_server_type(name)
  self.server_types.find { |type| type.name == name }
end