Class: Environment

Inherits:
Object
  • Object
show all
Defined in:
app/models/environment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, environment_name) ⇒ Environment

Returns a new instance of Environment.



3
4
5
6
# File 'app/models/environment.rb', line 3

def initialize(project, environment_name)
  @project = project
  @environment_name = environment_name
end

Instance Attribute Details

#environment_nameObject (readonly)

Returns the value of attribute environment_name.



8
9
10
# File 'app/models/environment.rb', line 8

def environment_name
  @environment_name
end

#projectObject (readonly)

Returns the value of attribute project.



8
9
10
# File 'app/models/environment.rb', line 8

def project
  @project
end

Instance Method Details

#dependency_version(dependency) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'app/models/environment.rb', line 27

def dependency_version(dependency)
  lockfile = read_file("Gemfile.lock")
  return nil unless lockfile

  dependency = dependency.to_s
  locked_gems = Bundler::LockfileParser.new(lockfile)
  spec = locked_gems.specs.find { |spec| spec.name == dependency }
  spec.version if spec
end

#headObject



14
15
16
17
# File 'app/models/environment.rb', line 14

def head
  return (environment_name == "Production" ? "c7c7380" : "98318a3") if Rails.env.development?
  @head ||= last_deploy.try(:commit)
end

#last_deployObject



10
11
12
# File 'app/models/environment.rb', line 10

def last_deploy
  @last_deploy ||= project.deploys.completed.to(environment_name).first
end

#read_file(path) ⇒ Object



19
20
21
22
23
# File 'app/models/environment.rb', line 19

def read_file(path)
  project.read_file(path, commit: head) if head
rescue Houston::Adapters::VersionControl::CommitNotFound
  nil
end