Class: Pkgr::Config
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Pkgr::Config
- Defined in:
- lib/pkgr/config.rb
Constant Summary collapse
- DISTRO_COMPATIBILITY_MAPPING =
{ "ubuntu-lucid" => "ubuntu-10.04", "ubuntu-precise" => "ubuntu-12.04", "debian-squeeze" => "debian-6", "debian-wheezy" => "debian-7" }
Class Method Summary collapse
Instance Method Summary collapse
- #addons ⇒ Object
- #after_hook ⇒ Object
- #after_install ⇒ Object
- #after_remove ⇒ Object
- #architecture ⇒ Object
- #before_hook ⇒ Object
- #before_install ⇒ Object
- #before_remove ⇒ Object
- #cli? ⇒ Boolean
- #crons ⇒ Object
- #delete(key) ⇒ Object
- #description ⇒ Object
- #each ⇒ Object
- #env ⇒ Object
- #errors ⇒ Object
- #group ⇒ Object
- #home ⇒ Object
- #homepage ⇒ Object
- #installer ⇒ Object
- #maintainer ⇒ Object
- #merge(other) ⇒ Object
- #safe_name ⇒ Object
- #sesame ⇒ Object
-
#to_args ⇒ Object
TODO: DRY this with cli.rb.
- #user ⇒ Object
- #valid? ⇒ Boolean
- #wizards ⇒ Object
Class Method Details
.load_file(path, distribution) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pkgr/config.rb', line 16 def load_file(path, distribution) config = YAML.load_file(path) || {} Pkgr.debug "Configuration from file: #{config.inspect} - Distribution: #{distribution.inspect}." targets = config.delete("targets") || {} # backward compatibility DISTRO_COMPATIBILITY_MAPPING.each do |from, to| if targets.has_key?(from) targets[to] = targets.delete(from) end end distro_config = targets[distribution.to_s] if distro_config.is_a?(Hash) distro_config.each do |k,v| config[k] = v end end self.new(config) end |
Instance Method Details
#addons ⇒ Object
125 126 127 128 129 130 |
# File 'lib/pkgr/config.rb', line 125 def addons # make proper Addon objects out of existing addon slugs (@table[:addons] || []).map do |addon_slug| Addon.new(addon_slug, addons_dir, self) end end |
#after_hook ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/pkgr/config.rb', line 166 def after_hook if after_precompile.nil? || after_precompile.empty? after_steps = self.after || [] if after_steps.empty? nil else tmpfile = Tempfile.new(["after_hook", ".sh"]) after_steps.each{|step| tmpfile.puts step} tmpfile.close tmpfile.path end else after_precompile end end |
#after_install ⇒ Object
188 189 190 191 |
# File 'lib/pkgr/config.rb', line 188 def after_install return nil if @table[:after_install].nil? Pathname.new(source_dir).join(@table[:after_install]).realpath.to_s end |
#after_remove ⇒ Object
198 199 200 201 |
# File 'lib/pkgr/config.rb', line 198 def after_remove return nil if @table[:after_remove].nil? Pathname.new(source_dir).join(@table[:after_remove]).realpath.to_s end |
#architecture ⇒ Object
90 91 92 |
# File 'lib/pkgr/config.rb', line 90 def architecture @table[:architecture] || "x86_64" end |
#before_hook ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/pkgr/config.rb', line 149 def before_hook if before_precompile.nil? || before_precompile.empty? before_steps = self.before || [] if before_steps.empty? nil else tmpfile = Tempfile.new(["before_hook", ".sh"]) before_steps.each{|step| tmpfile.puts step} tmpfile.close tmpfile.path end else before_precompile end end |
#before_install ⇒ Object
183 184 185 186 |
# File 'lib/pkgr/config.rb', line 183 def before_install return nil if @table[:before_install].nil? Pathname.new(source_dir).join(@table[:before_install]).realpath.to_s end |
#before_remove ⇒ Object
193 194 195 196 |
# File 'lib/pkgr/config.rb', line 193 def before_remove return nil if @table[:before_remove].nil? Pathname.new(source_dir).join(@table[:before_remove]).realpath.to_s end |
#cli? ⇒ Boolean
74 75 76 |
# File 'lib/pkgr/config.rb', line 74 def cli? @table.has_key?(:cli) ? @table[:cli] : true end |
#crons ⇒ Object
145 146 147 |
# File 'lib/pkgr/config.rb', line 145 def crons @table[:crons] || [] end |
#delete(key) ⇒ Object
66 67 68 |
# File 'lib/pkgr/config.rb', line 66 def delete(key) @table.delete(key) end |
#description ⇒ Object
98 99 100 |
# File 'lib/pkgr/config.rb', line 98 def description @table[:description] || "No description given" end |
#each ⇒ Object
59 60 61 62 63 64 |
# File 'lib/pkgr/config.rb', line 59 def each @table.each do |k,v| next if v.nil? yield k, v end end |
#env ⇒ Object
106 107 108 |
# File 'lib/pkgr/config.rb', line 106 def env @table[:env].is_a?(Pkgr::Env) ? @table[:env] : Pkgr::Env.new(@table[:env]) end |
#errors ⇒ Object
121 122 123 |
# File 'lib/pkgr/config.rb', line 121 def errors @errors ||= [] end |
#group ⇒ Object
86 87 88 |
# File 'lib/pkgr/config.rb', line 86 def group @table[:group] || user end |
#home ⇒ Object
78 79 80 |
# File 'lib/pkgr/config.rb', line 78 def home @table[:home] || "/opt/#{name}" end |
#homepage ⇒ Object
94 95 96 |
# File 'lib/pkgr/config.rb', line 94 def homepage @table[:homepage] || "http://example.com/no-uri-given" end |
#installer ⇒ Object
132 133 134 135 |
# File 'lib/pkgr/config.rb', line 132 def installer return nil if @table[:installer].nil? || @table[:installer] == false @table[:installer] end |
#maintainer ⇒ Object
102 103 104 |
# File 'lib/pkgr/config.rb', line 102 def maintainer @table[:maintainer] || "<someone@pkgr>" end |
#merge(other) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pkgr/config.rb', line 44 def merge(other) new_config = self.class.new self.each{|k,v| new_value = case v when Array v | (other.delete(k) || []) else v end new_config.send("#{k}=".to_sym, new_value) } other.each{|k,v| new_config.send("#{k}=".to_sym, v)} new_config end |
#safe_name ⇒ Object
70 71 72 |
# File 'lib/pkgr/config.rb', line 70 def safe_name name.gsub("-", "_") end |
#sesame ⇒ Object
40 41 42 |
# File 'lib/pkgr/config.rb', line 40 def sesame binding end |
#to_args ⇒ Object
TODO: DRY this with cli.rb
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/pkgr/config.rb', line 204 def to_args args = [ "--name \"#{name}\"", "--version \"#{version}\"", "--user \"#{user}\"", "--group \"#{group}\"", "--iteration \"#{iteration}\"", "--homepage \"#{homepage}\"", "--architecture \"#{architecture}\"", "--description \"#{description}\"", "--maintainer \"#{maintainer}\"", "--vendor \"#{vendor}\"" ] args.push "--dependencies #{dependencies.map{|d| "\"#{d}\""}.join}" unless dependencies.nil? || dependencies.empty? args.push "--build-dependencies #{build_dependencies.map{|d| "\"#{d}\""}.join}" unless build_dependencies.nil? || build_dependencies.empty? args.push "--compile-cache-dir \"#{compile_cache_dir}\"" unless compile_cache_dir.nil? || compile_cache_dir.empty? args.push "--before-precompile \"#{before_precompile}\"" unless before_precompile.nil? || before_precompile.empty? args.push "--after-precompile \"#{after_precompile}\"" unless after_precompile.nil? || after_precompile.empty? args.push "--before-install \"#{before_install}\"" unless before_install.nil? || before_install.empty? args.push "--after-install \"#{after_install}\"" unless after_install.nil? || after_install.empty? args.push "--before-remove \"#{before_remove}\"" unless before_remove.nil? || before_remove.empty? args.push "--after-remove \"#{after_remove}\"" unless after_remove.nil? || after_remove.empty? args.push "--license \"#{license}\"" unless license.nil? || license.empty? args.push "--buildpack \"#{buildpack}\"" unless buildpack.nil? || buildpack.empty? args.push "--buildpack_list \"#{buildpack_list}\"" unless buildpack_list.nil? || buildpack_list.empty? args.push "--force-os \"#{force_os}\"" unless force_os.nil? || force_os.empty? args.push "--runner \"#{runner}\"" unless runner.nil? || runner.empty? args.push "--env #{env.variables.map{|v| "\"#{v}\""}.join(" ")}" if env.present? args.push "--auto" if auto args.push "--verbose" if verbose args.push "--store-cache" if store_cache args.push "--debug" if debug args.push "--verify" if verify args.push "--no-clean" if !clean args.push "--no-edge" if !edge args end |
#user ⇒ Object
82 83 84 |
# File 'lib/pkgr/config.rb', line 82 def user @table[:user] || name end |
#valid? ⇒ Boolean
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/pkgr/config.rb', line 110 def valid? @errors = [] @errors.push("name can't be blank") if name.nil? || name.empty? @errors.push("version can't be blank") if version.nil? || version.empty? @errors.push("version must start with a digit") if !version.empty? && version !~ /^\d/ @errors.push("iteration can't be blank") if iteration.nil? || iteration.empty? @errors.push("user can't be blank") if user.nil? || user.empty? @errors.push("group can't be blank") if group.nil? || group.empty? @errors.empty? end |