Class: Librarian::Environment

Inherits:
Object
  • Object
show all
Includes:
Support::AbstractMethod
Defined in:
lib/librarian/environment.rb,
lib/librarian/environment/runtime_cache.rb

Direct Known Subclasses

Mock::Environment

Defined Under Namespace

Classes: RuntimeCache

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::AbstractMethod

included

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(options = { })
  @pwd = options.fetch(:pwd) { Dir.pwd }
  @env = options.fetch(:env) { ENV.to_hash }
  @home = options.fetch(:home) { default_home }
  @project_path = options[:project_path]
  @runtime_cache = RuntimeCache.new
end

Instance Attribute Details

#runtime_cacheObject (readonly)

Returns the value of attribute runtime_cache


26
27
28
# File 'lib/librarian/environment.rb', line 26

def runtime_cache
  @runtime_cache
end

#uiObject

Returns the value of attribute ui


25
26
27
# File 'lib/librarian/environment.rb', line 25

def ui
  @ui
end

Instance Method Details

#adapter_moduleObject


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_nameObject


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_versionObject


87
88
89
90
# File 'lib/librarian/environment.rb', line 87

def adapter_version
  implementation? or return
  adapter_module::VERSION
end

#cache_pathObject


127
128
129
# File 'lib/librarian/environment.rb', line 127

def cache_path
  tmp_path.join("librarian/cache")
end

#config_dbObject


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_keysObject


159
160
161
162
# File 'lib/librarian/environment.rb', line 159

def config_keys
  %[
  ]
end

#default_specfile_nameObject


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_classObject


151
152
153
# File 'lib/librarian/environment.rb', line 151

def dsl_class
  adapter_module::Dsl
end

#ephemeral_lockfileObject


104
105
106
# File 'lib/librarian/environment.rb', line 104

def ephemeral_lockfile
  Lockfile.new(self, nil)
end

#http_proxy_uriObject

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

#inspectObject


191
192
193
# File 'lib/librarian/environment.rb', line 191

def inspect
  "#<#{self.class}:0x#{__id__.to_s(16)}>"
end

#lockObject


143
144
145
# File 'lib/librarian/environment.rb', line 143

def lock
  lockfile.read
end

#lockfileObject


100
101
102
# File 'lib/librarian/environment.rb', line 100

def lockfile
  Lockfile.new(self, lockfile_path)
end

#lockfile_nameObject


92
93
94
# File 'lib/librarian/environment.rb', line 92

def lockfile_name
  config_db.lockfile_name
end

#lockfile_pathObject


96
97
98
# File 'lib/librarian/environment.rb', line 96

def lockfile_path
  config_db.lockfile_path
end

#loggerObject


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_pathObject


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(options = { })
  Resolver.new(self, resolver_options.merge(options))
end

#resolver_optionsObject


112
113
114
115
116
# File 'lib/librarian/environment.rb', line 112

def resolver_options
  {
    :cyclic => resolver_permit_cyclic_reslutions?,
  }
end

#resolver_permit_cyclic_reslutions?Boolean

Returns:

  • (Boolean)

118
119
120
# File 'lib/librarian/environment.rb', line 118

def resolver_permit_cyclic_reslutions?
  false
end

#scratch_pathObject


131
132
133
# File 'lib/librarian/environment.rb', line 131

def scratch_path
  tmp_path.join("librarian/scratch")
end

#specObject


139
140
141
# File 'lib/librarian/environment.rb', line 139

def spec
  specfile.read
end

#specfileObject


73
74
75
# File 'lib/librarian/environment.rb', line 73

def specfile
  Specfile.new(self, specfile_path)
end

#specfile_nameObject


65
66
67
# File 'lib/librarian/environment.rb', line 65

def specfile_name
  config_db.specfile_name
end

#specfile_pathObject


69
70
71
# File 'lib/librarian/environment.rb', line 69

def specfile_path
  config_db.specfile_path
end

#tmp_pathObject


122
123
124
125
# File 'lib/librarian/environment.rb', line 122

def tmp_path
  part = config_db["tmp"] || "tmp"
  project_path.join(part)
end

#versionObject


155
156
157
# File 'lib/librarian/environment.rb', line 155

def version
  VERSION
end