Class: Librarian::Environment
- Inherits:
-
Object
- Object
- Librarian::Environment
- Includes:
- Support::AbstractMethod
- Defined in:
- lib/librarian/environment.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ui ⇒ Object
Returns the value of attribute ui.
Instance Method Summary collapse
- #adapter_name ⇒ Object
- #cache_path ⇒ Object
- #config_db ⇒ Object
- #config_keys ⇒ Object
- #default_specfile_name ⇒ Object
- #dsl(*args, &block) ⇒ Object
- #dsl_class ⇒ Object
- #ephemeral_lockfile ⇒ Object
-
#http_proxy_uri ⇒ Object
The HTTP proxy specified in the environment variables: * HTTP_PROXY * HTTP_PROXY_USER * HTTP_PROXY_PASS Adapted from: github.com/rubygems/rubygems/blob/v1.8.24/lib/rubygems/remote_fetcher.rb#L276-293.
-
#initialize(options = { }) ⇒ Environment
constructor
A new instance of Environment.
- #lock ⇒ Object
- #lockfile ⇒ Object
- #lockfile_name ⇒ Object
- #lockfile_path ⇒ Object
- #logger ⇒ Object
- #net_http_class(host) ⇒ Object
- #project_path ⇒ Object
- #project_relative_path_to(path) ⇒ Object
- #resolver ⇒ Object
- #scratch_path ⇒ Object
- #spec ⇒ Object
- #specfile ⇒ Object
- #specfile_name ⇒ Object
- #specfile_path ⇒ Object
- #tmp_path ⇒ Object
- #version ⇒ Object
Methods included from Support::AbstractMethod
Constructor Details
#initialize(options = { }) ⇒ Environment
Returns a new instance of Environment.
26 27 28 29 30 31 32 |
# File 'lib/librarian/environment.rb', line 26 def initialize( = { }) @pwd = .fetch(:pwd) { Dir.pwd } @env = .fetch(:env) { ENV.to_hash } @home = .fetch(:home) { File.("~") } @project_path = [:project_path] @specfile_name = [:specfile_name] end |
Instance Attribute Details
#ui ⇒ Object
Returns the value of attribute ui.
22 23 24 |
# File 'lib/librarian/environment.rb', line 22 def ui @ui end |
Instance Method Details
#adapter_name ⇒ Object
73 74 75 |
# File 'lib/librarian/environment.rb', line 73 def adapter_name nil end |
#cache_path ⇒ Object
102 103 104 |
# File 'lib/librarian/environment.rb', line 102 def cache_path tmp_path.join("librarian/cache") end |
#config_db ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/librarian/environment.rb', line 38 def config_db @config_db ||= begin Config::Database.new(adapter_name, :pwd => @pwd, :env => @env, :home => @home, :project_path => @project_path, :specfile_name => default_specfile_name ) end end |
#config_keys ⇒ Object
134 135 136 137 |
# File 'lib/librarian/environment.rb', line 134 def config_keys %[ ] end |
#default_specfile_name ⇒ Object
50 51 52 53 54 55 |
# File 'lib/librarian/environment.rb', line 50 def default_specfile_name @default_specfile_name ||= begin capped = adapter_name.capitalize "#{capped}file" end end |
#dsl(*args, &block) ⇒ Object
122 123 124 |
# File 'lib/librarian/environment.rb', line 122 def dsl(*args, &block) dsl_class.run(self, *args, &block) end |
#dsl_class ⇒ Object
126 127 128 |
# File 'lib/librarian/environment.rb', line 126 def dsl_class self.class.name.split("::")[0 ... -1].inject(Object, &:const_get)::Dsl end |
#ephemeral_lockfile ⇒ Object
89 90 91 |
# File 'lib/librarian/environment.rb', line 89 def ephemeral_lockfile Lockfile.new(self, nil) end |
#http_proxy_uri ⇒ Object
The HTTP proxy specified in the environment variables:
-
HTTP_PROXY
-
HTTP_PROXY_USER
-
HTTP_PROXY_PASS
Adapted from:
https://github.com/rubygems/rubygems/blob/v1.8.24/lib/rubygems/remote_fetcher.rb#L276-293
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/librarian/environment.rb', line 145 def http_proxy_uri @http_proxy_uri ||= begin keys = %w( HTTP_PROXY HTTP_PROXY_USER HTTP_PROXY_PASS ) env = Hash[ENV. map{|k, v| [k.upcase, v]}. select{|k, v| keys.include?(k)}. reject{|k, v| v.nil? || v.empty?}] uri = env["HTTP_PROXY"] or return uri = "http://#{uri}" unless uri =~ /^(https?|ftp|file):/ uri = URI.parse(uri) uri.user ||= env["HTTP_PROXY_USER"] uri.password ||= env["HTTP_PROXY_PASS"] uri end end |
#lock ⇒ Object
118 119 120 |
# File 'lib/librarian/environment.rb', line 118 def lock lockfile.read end |
#lockfile ⇒ Object
85 86 87 |
# File 'lib/librarian/environment.rb', line 85 def lockfile Lockfile.new(self, lockfile_path) end |
#lockfile_name ⇒ Object
77 78 79 |
# File 'lib/librarian/environment.rb', line 77 def lockfile_name config_db.lockfile_name end |
#lockfile_path ⇒ Object
81 82 83 |
# File 'lib/librarian/environment.rb', line 81 def lockfile_path config_db.lockfile_path end |
#logger ⇒ Object
34 35 36 |
# File 'lib/librarian/environment.rb', line 34 def logger @logger ||= Logger.new(self) end |
#net_http_class(host) ⇒ Object
162 163 164 165 166 167 168 169 |
# File 'lib/librarian/environment.rb', line 162 def net_http_class(host) return Net::HTTP if no_proxy?(host) @net_http_class ||= begin p = http_proxy_uri p ? Net::HTTP::Proxy(p.host, p.port, p.user, p.password) : Net::HTTP end end |
#project_path ⇒ Object
57 58 59 |
# File 'lib/librarian/environment.rb', line 57 def project_path config_db.project_path end |
#project_relative_path_to(path) ⇒ Object
110 111 112 |
# File 'lib/librarian/environment.rb', line 110 def project_relative_path_to(path) Pathname.new(path).relative_path_from(project_path) end |
#resolver ⇒ Object
93 94 95 |
# File 'lib/librarian/environment.rb', line 93 def resolver Resolver.new(self) end |
#scratch_path ⇒ Object
106 107 108 |
# File 'lib/librarian/environment.rb', line 106 def scratch_path tmp_path.join("librarian/scratch") end |
#spec ⇒ Object
114 115 116 |
# File 'lib/librarian/environment.rb', line 114 def spec specfile.read end |
#specfile ⇒ Object
69 70 71 |
# File 'lib/librarian/environment.rb', line 69 def specfile Specfile.new(self, specfile_path) end |
#specfile_name ⇒ Object
61 62 63 |
# File 'lib/librarian/environment.rb', line 61 def specfile_name config_db.specfile_name end |
#specfile_path ⇒ Object
65 66 67 |
# File 'lib/librarian/environment.rb', line 65 def specfile_path config_db.specfile_path end |
#tmp_path ⇒ Object
97 98 99 100 |
# File 'lib/librarian/environment.rb', line 97 def tmp_path part = config_db["tmp"] || "tmp" project_path.join(part) end |
#version ⇒ Object
130 131 132 |
# File 'lib/librarian/environment.rb', line 130 def version VERSION end |