Class: Skynet::Builder::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/skynet/builder/base.rb

Direct Known Subclasses

Jekyll, Static

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, config) ⇒ Base

Returns a new instance of Base.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/skynet/builder/base.rb', line 23

def initialize(app, config)
  self.app = app
  @config  = config
  @source  = File.join Dir.pwd, app, '.'
  @key     = config[:key]

  self.branches = config[:branches]
  if branches.present? && branches.first.present?
    self.branch      = branches.first[0]
    self.destination = branches.first[1]
  end
  self.url        = config[:url]
  self.type       = config[:type]
  self.repository = config[:repository]
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



13
14
15
# File 'lib/skynet/builder/base.rb', line 13

def app
  @app
end

#branchObject

Returns the value of attribute branch.



13
14
15
# File 'lib/skynet/builder/base.rb', line 13

def branch
  @branch
end

#branchesObject

Returns the value of attribute branches.



13
14
15
# File 'lib/skynet/builder/base.rb', line 13

def branches
  @branches
end

#destinationObject

Returns the value of attribute destination.



13
14
15
# File 'lib/skynet/builder/base.rb', line 13

def destination
  @destination
end

#keyObject (readonly)

Returns the value of attribute key.



14
15
16
# File 'lib/skynet/builder/base.rb', line 14

def key
  @key
end

#repositoryObject

Returns the value of attribute repository.



13
14
15
# File 'lib/skynet/builder/base.rb', line 13

def repository
  @repository
end

#sourceObject (readonly)

Returns the value of attribute source.



14
15
16
# File 'lib/skynet/builder/base.rb', line 14

def source
  @source
end

#typeObject

Returns the value of attribute type.



13
14
15
# File 'lib/skynet/builder/base.rb', line 13

def type
  @type
end

#urlObject

Returns the value of attribute url.



13
14
15
# File 'lib/skynet/builder/base.rb', line 13

def url
  @url
end

Instance Method Details

#build(branch = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/skynet/builder/base.rb', line 39

def build(branch=nil)
  if branch.present?
    return if branches[branch].blank?
    self.branches = { branch => branches[branch] }
  end

  unless valid?
    Skynet.logger.error "Configuration error for #{app} (branch: #{branch})"
    Skynet.logger.error errors.full_messages.join '. '
    raise ArgumentError
  end

  branches.each_pair do |branch, destination|
    self.branch      = branch.to_s
    self.destination = destination

    if valid?
      Skynet.logger.info "#{type} running for #{app} (branch: #{branch})"
    else
      Skynet.logger.error "Configuration error for #{app} (branch: #{branch})"
      Skynet.logger.error errors.full_messages.join '. '
      raise ArgumentError
    end

    build_repository
    execute
  end
end