Class: Berkshelf::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/berkshelf/uploader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(berksfile, *args) ⇒ Uploader

Returns a new instance of Uploader.


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/berkshelf/uploader.rb', line 8

def initialize(berksfile, *args)
  @berksfile = berksfile
  @lockfile  = berksfile.lockfile

  @options = {
    force:          false,
    freeze:         true,
    halt_on_frozen: false,
    validate:       true,
  }.merge(args.last.is_a?(Hash) ? args.pop : {})

  @names = Array(args).flatten
end

Instance Attribute Details

#berksfileObject (readonly)

Returns the value of attribute berksfile


3
4
5
# File 'lib/berkshelf/uploader.rb', line 3

def berksfile
  @berksfile
end

#lockfileObject (readonly)

Returns the value of attribute lockfile


4
5
6
# File 'lib/berkshelf/uploader.rb', line 4

def lockfile
  @lockfile
end

#namesObject (readonly)

Returns the value of attribute names


6
7
8
# File 'lib/berkshelf/uploader.rb', line 6

def names
  @names
end

#optionsObject (readonly)

Returns the value of attribute options


5
6
7
# File 'lib/berkshelf/uploader.rb', line 5

def options
  @options
end

Instance Method Details

#runObject


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/berkshelf/uploader.rb', line 22

def run
  Berkshelf.log.info "Uploading cookbooks"

  cookbooks = if names.empty?
                Berkshelf.log.debug "  No names given, using all cookbooks"
                filtered_cookbooks
              else
                Berkshelf.log.debug "  Names given (#{names.join(', ')})"
                names.map { |name| lockfile.retrieve(name) }
              end

  # Perform all validations first to prevent partially uploaded cookbooks
  Validator.validate_files(cookbooks)

  upload(cookbooks)
  cookbooks
end