Class: Vendor::VendorSpec::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/vendor_spec/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vendor_spec) ⇒ Builder

Returns a new instance of Builder.



17
18
19
20
21
22
23
24
# File 'lib/vendor/vendor_spec/builder.rb', line 17

def initialize(vendor_spec)
  @folder = File.expand_path(File.join(vendor_spec, '..'))
  @vendor_spec = Vendor::Spec.load vendor_spec

  @name = safe_filename(@vendor_spec.name)
  @version = safe_filename(@vendor_spec.version)
  @filename = "#{@name}-#{@version}.vendor"
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



14
15
16
# File 'lib/vendor/vendor_spec/builder.rb', line 14

def filename
  @filename
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/vendor/vendor_spec/builder.rb', line 12

def name
  @name
end

#vendor_specObject (readonly)

Returns the value of attribute vendor_spec.



15
16
17
# File 'lib/vendor/vendor_spec/builder.rb', line 15

def vendor_spec
  @vendor_spec
end

#versionObject (readonly)

Returns the value of attribute version.



13
14
15
# File 'lib/vendor/vendor_spec/builder.rb', line 13

def version
  @version
end

Instance Method Details

#buildObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vendor/vendor_spec/builder.rb', line 26

def build
  tmpdir = Dir.mktmpdir(@filename)

  vendor_file = File.join(tmpdir, "vendor.json")
  data_dir = File.join(tmpdir, "data")
  data_files = copy_files(data_dir)

  open(vendor_file, 'w+') { |f| f << @vendor_spec.to_json }

  FileUtils.rm(@filename) if File.exist?(@filename)

  zip_file @filename, [ vendor_file, *data_files ], tmpdir

  true
end