Class: Capifig::Configuration

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, path) ⇒ Configuration

Returns a new instance of Configuration.



12
13
14
15
# File 'lib/capifig/configuration.rb', line 12

def initialize(configuration, path)
  @cap = configuration
  @path = path
end

Instance Attribute Details

#capObject

Returns the value of attribute cap.



10
11
12
# File 'lib/capifig/configuration.rb', line 10

def cap
  @cap
end

#pathObject

Returns the value of attribute path.



9
10
11
# File 'lib/capifig/configuration.rb', line 9

def path
  @path
end

Class Method Details

.deploy(configuration, path) ⇒ Object



5
6
7
# File 'lib/capifig/configuration.rb', line 5

def self.deploy configuration, path
  Configuration.new(configuration, path).deploy
end

Instance Method Details

#deployObject



39
40
41
42
43
44
# File 'lib/capifig/configuration.rb', line 39

def deploy
  files.each do |f|
    cap.upload(f, remote_path(f))
  end

end

#filesObject

Returns an array of local paths of files to upload



18
19
20
21
22
23
# File 'lib/capifig/configuration.rb', line 18

def files
  # Alternative: this glob also works, but may include temporary files:
  #files = Dir.glob("#@path/**/*", File::FNM_DOTMATCH).select { |f| File.file?(f) }
  files = `git ls-files #@path`.split($/)
  files.sort
end

#relative_path(file) ⇒ Object

Given a local path, returns the relative path to the file

Raises:

  • (ArgumentError)


32
33
34
35
36
37
# File 'lib/capifig/configuration.rb', line 32

def relative_path(file)
  path = Pathname.new(file).relative_path_from(Pathname.new(@path)).to_s
  # For security reasons, we check that the path does not contain any ..'s
  raise ArgumentError, "File '#{file}' is not in '#@path'" if path.include? '..'
  path
end

#remote_path(file) ⇒ Object

Given a local path, returns the remote path for the file



26
27
28
29
# File 'lib/capifig/configuration.rb', line 26

def remote_path(file)
  path = Pathname.new(cap.fetch(:release_path)) + relative_path(file)
  path.to_s
end