Class: Librarian::Environment
- Inherits:
-
Object
- Object
- Librarian::Environment
- Includes:
- Support::AbstractMethod
- Defined in:
- lib/librarian/environment.rb,
lib/librarian/environment/runtime_cache.rb
Direct Known Subclasses
Defined Under Namespace
Classes: RuntimeCache
Instance Attribute Summary collapse
-
#runtime_cache ⇒ Object
readonly
Returns the value of attribute runtime_cache.
-
#ui ⇒ Object
Returns the value of attribute ui.
Instance Method Summary collapse
- #adapter_module ⇒ Object
- #adapter_name ⇒ Object
- #adapter_version ⇒ 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.
- #inspect ⇒ Object
- #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(options = { }) ⇒ Object
- #resolver_options ⇒ Object
- #resolver_permit_cyclic_reslutions? ⇒ Boolean
- #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.
30 31 32 33 34 35 36 |
# File 'lib/librarian/environment.rb', line 30 def initialize( = { }) @pwd = .fetch(:pwd) { Dir.pwd } @env = .fetch(:env) { ENV.to_hash } @home = .fetch(:home) { default_home } @project_path = [:project_path] @runtime_cache = RuntimeCache.new end |
Instance Attribute Details
#runtime_cache ⇒ Object (readonly)
Returns the value of attribute runtime_cache.
26 27 28 |
# File 'lib/librarian/environment.rb', line 26 def runtime_cache @runtime_cache end |
#ui ⇒ Object
Returns the value of attribute ui.
25 26 27 |
# File 'lib/librarian/environment.rb', line 25 def ui @ui end |
Instance Method Details
#adapter_module ⇒ Object
77 78 79 80 |
# File 'lib/librarian/environment.rb', line 77 def adapter_module implementation? or return self.class.name.split("::")[0 ... -1].inject(Object, &:const_get) end |
#adapter_name ⇒ Object
82 83 84 85 |
# File 'lib/librarian/environment.rb', line 82 def adapter_name implementation? or return Helpers.camel_cased_to_dasherized(self.class.name.split("::")[-2]) end |
#adapter_version ⇒ Object
87 88 89 90 |
# File 'lib/librarian/environment.rb', line 87 def adapter_version implementation? or return adapter_module::VERSION end |
#cache_path ⇒ Object
127 128 129 |
# File 'lib/librarian/environment.rb', line 127 def cache_path tmp_path.join("librarian/cache") end |
#config_db ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/librarian/environment.rb', line 42 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
159 160 161 162 |
# File 'lib/librarian/environment.rb', line 159 def config_keys %[ ] end |
#default_specfile_name ⇒ Object
54 55 56 57 58 59 |
# File 'lib/librarian/environment.rb', line 54 def default_specfile_name @default_specfile_name ||= begin capped = adapter_name.capitalize "#{capped}file" end end |
#dsl(*args, &block) ⇒ Object
147 148 149 |
# File 'lib/librarian/environment.rb', line 147 def dsl(*args, &block) dsl_class.run(self, *args, &block) end |
#dsl_class ⇒ Object
151 152 153 |
# File 'lib/librarian/environment.rb', line 151 def dsl_class adapter_module::Dsl end |
#ephemeral_lockfile ⇒ Object
104 105 106 |
# File 'lib/librarian/environment.rb', line 104 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
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/librarian/environment.rb', line 170 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 |
#inspect ⇒ Object
191 192 193 |
# File 'lib/librarian/environment.rb', line 191 def inspect "#<#{self.class}:0x#{__id__.to_s(16)}>" end |
#lock ⇒ Object
143 144 145 |
# File 'lib/librarian/environment.rb', line 143 def lock lockfile.read end |
#lockfile ⇒ Object
100 101 102 |
# File 'lib/librarian/environment.rb', line 100 def lockfile Lockfile.new(self, lockfile_path) end |
#lockfile_name ⇒ Object
92 93 94 |
# File 'lib/librarian/environment.rb', line 92 def lockfile_name config_db.lockfile_name end |
#lockfile_path ⇒ Object
96 97 98 |
# File 'lib/librarian/environment.rb', line 96 def lockfile_path config_db.lockfile_path end |
#logger ⇒ Object
38 39 40 |
# File 'lib/librarian/environment.rb', line 38 def logger @logger ||= Logger.new(self) end |
#net_http_class(host) ⇒ Object
187 188 189 |
# File 'lib/librarian/environment.rb', line 187 def net_http_class(host) no_proxy?(host) ? Net::HTTP : net_http_default_class end |
#project_path ⇒ Object
61 62 63 |
# File 'lib/librarian/environment.rb', line 61 def project_path config_db.project_path end |
#project_relative_path_to(path) ⇒ Object
135 136 137 |
# File 'lib/librarian/environment.rb', line 135 def project_relative_path_to(path) Pathname.new(path).relative_path_from(project_path) end |
#resolver(options = { }) ⇒ Object
108 109 110 |
# File 'lib/librarian/environment.rb', line 108 def resolver( = { }) Resolver.new(self, .merge()) end |
#resolver_options ⇒ Object
112 113 114 115 116 |
# File 'lib/librarian/environment.rb', line 112 def { :cyclic => resolver_permit_cyclic_reslutions?, } end |
#resolver_permit_cyclic_reslutions? ⇒ Boolean
118 119 120 |
# File 'lib/librarian/environment.rb', line 118 def resolver_permit_cyclic_reslutions? false end |
#scratch_path ⇒ Object
131 132 133 |
# File 'lib/librarian/environment.rb', line 131 def scratch_path tmp_path.join("librarian/scratch") end |
#spec ⇒ Object
139 140 141 |
# File 'lib/librarian/environment.rb', line 139 def spec specfile.read end |
#specfile ⇒ Object
73 74 75 |
# File 'lib/librarian/environment.rb', line 73 def specfile Specfile.new(self, specfile_path) end |
#specfile_name ⇒ Object
65 66 67 |
# File 'lib/librarian/environment.rb', line 65 def specfile_name config_db.specfile_name end |
#specfile_path ⇒ Object
69 70 71 |
# File 'lib/librarian/environment.rb', line 69 def specfile_path config_db.specfile_path end |
#tmp_path ⇒ Object
122 123 124 125 |
# File 'lib/librarian/environment.rb', line 122 def tmp_path part = config_db["tmp"] || "tmp" project_path.join(part) end |
#version ⇒ Object
155 156 157 |
# File 'lib/librarian/environment.rb', line 155 def version VERSION end |