Class: Kleiber::Project

Inherits:
Object
  • Object
show all
Includes:
Commands
Defined in:
lib/kleiber/project.rb

Overview

Provides api to control such project

Author:

Constant Summary collapse

VARS =
{
  host: 'HOST',
  guest_port: 'PORT'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commands

#apply_env_line, #handle_halt, #handle_reload, #handle_ssh, #handle_up, #in_machine, #scriptify, #ssh_exec_line, #tasks_line, #terminal_execute, #vagrant, #vagrant_, #vagrant_destroy, #vagrant_halt, #vagrant_provision, #vagrant_reload, #vagrant_ssh, #vagrant_up, #with_tmpfile_script

Constructor Details

#initialize(settings) ⇒ Project

Returns a new instance of Project.



9
10
11
12
13
14
15
16
17
18
# File 'lib/kleiber/project.rb', line 9

def initialize(settings)
  @name       = settings[:name]
  @prefix     = settings[:prefix]
  @path       = settings[:path]
  @guest_port = settings[:guest_port]
  @host_port  = settings[:host_port]
  @host       = settings[:host]
  @tasks      = settings[:tasks]
  @env        = settings[:env]
end

Instance Attribute Details

#guest_portObject (readonly)

Returns the value of attribute guest_port.



8
9
10
# File 'lib/kleiber/project.rb', line 8

def guest_port
  @guest_port
end

#hostObject (readonly)

Returns the value of attribute host.



8
9
10
# File 'lib/kleiber/project.rb', line 8

def host
  @host
end

#host_portObject (readonly)

Returns the value of attribute host_port.



8
9
10
# File 'lib/kleiber/project.rb', line 8

def host_port
  @host_port
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/kleiber/project.rb', line 8

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/kleiber/project.rb', line 8

def path
  @path
end

#prefixObject (readonly)

Returns the value of attribute prefix.



8
9
10
# File 'lib/kleiber/project.rb', line 8

def prefix
  @prefix
end

Instance Method Details

#command_with(command, params) ⇒ String

Returns command with option to run

Parameters:

  • params (Hash)

    params need run with

Returns:

  • (String)

    command line



50
51
52
# File 'lib/kleiber/project.rb', line 50

def command_with(command, params)
  ["cd #{path}", send("handle_#{command}", params)].join(' && ')
end

#envObject



25
26
27
# File 'lib/kleiber/project.rb', line 25

def env
  @env || {}
end

#environmentHash

Return env variables of this project

Returns:

  • (Hash)


35
36
37
38
39
# File 'lib/kleiber/project.rb', line 35

def environment
  @env_vars ||= VARS.reduce({}) do |hash, (key, value)|
    hash.merge("#{prefix}_#{value}" => send(key))
  end.merge(env)
end

#tasksObject



29
30
31
# File 'lib/kleiber/project.rb', line 29

def tasks
  @tasks || {}
end