Class: PrePackager::Application
- Inherits:
-
Object
- Object
- PrePackager::Application
- Includes:
- Executor
- Defined in:
- lib/pre-packager.rb
Constant Summary collapse
Instance Method Summary collapse
- #create_package(opts) ⇒ Object
- #download_from(url) ⇒ Object
-
#initialize(values = {}) ⇒ Application
constructor
A new instance of Application.
- #with_templates(from, to) ⇒ Object
Methods included from Executor
Constructor Details
#initialize(values = {}) ⇒ Application
Returns a new instance of Application.
107 108 109 110 |
# File 'lib/pre-packager.rb', line 107 def initialize values={} ParamsAssertion.new(:name).included? values @interpolator = Interpolator.new values end |
Instance Method Details
#create_package(opts) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/pre-packager.rb', line 135 def create_package opts ParamsAssertion.new(:version).included? opts name = interpolate '$name' paths = Pathname.new(name). children. map(&:basename). map(&:to_s). join ' ' valid_fields = Proc.new { |k, v| @@VALID_FIELDS.include? k} compose_field = Proc.new { |k, v| %Q|--#{k} "#{v}"|} fields = opts. select(&valid_fields). map(&compose_field). join ' ' cmd = interpolate %Q| fpm -s dir -t deb -C #{name} -n #{name} -v #{opts[:version]} -a all #{fields} #{paths} | if opts[:dry_run] @@LOGGER.info "Command to generate package: #{cmd}" else execute cmd end end |
#download_from(url) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/pre-packager.rb', line 112 def download_from url uri = URI.parse interpolate(url) file = File.basename uri.path @@LOGGER.info "Downloading #{uri}" execute "wget -nc #{uri}" if block_given? yield Package.new file, @interpolator self else file end end |
#with_templates(from, to) ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/pre-packager.rb', line 127 def with_templates from, to FileUtils.mkdir_p interpolate("$name/#{to}") target = interpolate("$name/#{to}") Dir.glob(from).each {|f| FileUtils.cp_r f, target} self end |