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
- #after_hook ⇒ Object
- #after_install ⇒ Object
- #architecture ⇒ Object
- #before_hook ⇒ Object
- #before_install ⇒ Object
- #delete(key) ⇒ Object
- #description ⇒ Object
- #each ⇒ Object
- #env ⇒ Object
- #errors ⇒ Object
- #group ⇒ Object
- #home ⇒ Object
- #homepage ⇒ Object
- #maintainer ⇒ Object
- #merge(other) ⇒ Object
- #sesame ⇒ Object
-
#to_args ⇒ Object
TODO: DRY this with cli.rb.
- #user ⇒ Object
- #valid? ⇒ Boolean
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 |
# 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 (targets[distribution.to_s] || {}).each do |k,v| config[k] = v end self.new(config) end |
Instance Method Details
#after_hook ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/pkgr/config.rb', line 131 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
153 154 155 156 |
# File 'lib/pkgr/config.rb', line 153 def after_install return nil if @table[:after_install].nil? Pathname.new(source_dir).join(@table[:after_install]).realpath.to_s end |
#architecture ⇒ Object
79 80 81 |
# File 'lib/pkgr/config.rb', line 79 def architecture @table[:architecture] || "x86_64" end |
#before_hook ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/pkgr/config.rb', line 114 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
148 149 150 151 |
# File 'lib/pkgr/config.rb', line 148 def before_install return nil if @table[:before_install].nil? Pathname.new(source_dir).join(@table[:before_install]).realpath.to_s end |
#delete(key) ⇒ Object
63 64 65 |
# File 'lib/pkgr/config.rb', line 63 def delete(key) @table.delete(key) end |
#description ⇒ Object
87 88 89 |
# File 'lib/pkgr/config.rb', line 87 def description @table[:description] || "No description given" end |
#each ⇒ Object
56 57 58 59 60 61 |
# File 'lib/pkgr/config.rb', line 56 def each @table.each do |k,v| next if v.nil? yield k, v end end |
#errors ⇒ Object
110 111 112 |
# File 'lib/pkgr/config.rb', line 110 def errors @errors ||= [] end |
#group ⇒ Object
75 76 77 |
# File 'lib/pkgr/config.rb', line 75 def group @table[:group] || user end |
#home ⇒ Object
67 68 69 |
# File 'lib/pkgr/config.rb', line 67 def home "/opt/#{name}" end |
#homepage ⇒ Object
83 84 85 |
# File 'lib/pkgr/config.rb', line 83 def homepage @table[:homepage] || "http://example.com/no-uri-given" end |
#maintainer ⇒ Object
91 92 93 |
# File 'lib/pkgr/config.rb', line 91 def maintainer @table[:maintainer] || "<someone@pkgr>" end |
#merge(other) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pkgr/config.rb', line 41 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 |
#sesame ⇒ Object
37 38 39 |
# File 'lib/pkgr/config.rb', line 37 def sesame binding end |
#to_args ⇒ Object
TODO: DRY this with cli.rb
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/pkgr/config.rb', line 159 def to_args args = [ "--name \"#{name}\"", "--version \"#{version}\"", "--user \"#{user}\"", "--group \"#{group}\"", "--iteration \"#{iteration}\"", "--homepage \"#{homepage}\"", "--architecture \"#{architecture}\"", "--description \"#{description}\"", "--maintainer \"#{maintainer}\"" ] 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 "--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 "--debug" if debug args.push "--no-clean" if !clean args.push "--no-edge" if !edge args end |
#user ⇒ Object
71 72 73 |
# File 'lib/pkgr/config.rb', line 71 def user @table[:user] || name end |
#valid? ⇒ Boolean
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/pkgr/config.rb', line 99 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 |