Class: RailVerdict::RunContext
- Inherits:
-
Object
- Object
- RailVerdict::RunContext
- Defined in:
- lib/rail_verdict/run_context.rb
Constant Summary collapse
- DETERMINISTIC_INPUTS =
{ "locale" => "C.UTF-8", "timezone" => "UTC", "ordering" => "canonical-v1" }.freeze
- GEMFILE_LOCK_RAILS =
/^\s+rails \((\d+\.\d+\.\d+(?:\.\d+)*)\)/- GEMFILE_LOCK_RUBY =
/^\s+ruby (\d+\.\d+\.\d+)/
Instance Attribute Summary collapse
-
#analyzer_versions ⇒ Object
readonly
Returns the value of attribute analyzer_versions.
-
#analyzers ⇒ Object
readonly
Returns the value of attribute analyzers.
-
#configuration_digest ⇒ Object
readonly
Returns the value of attribute configuration_digest.
-
#configuration_mode ⇒ Object
readonly
Returns the value of attribute configuration_mode.
-
#deterministic_inputs ⇒ Object
readonly
Returns the value of attribute deterministic_inputs.
-
#git_context ⇒ Object
readonly
Returns the value of attribute git_context.
-
#rails_version ⇒ Object
readonly
Returns the value of attribute rails_version.
-
#repository_root ⇒ Object
readonly
Returns the value of attribute repository_root.
-
#revision ⇒ Object
readonly
Returns the value of attribute revision.
-
#ruby_version ⇒ Object
readonly
Returns the value of attribute ruby_version.
-
#target_ruby_version ⇒ Object
readonly
Returns the value of attribute target_ruby_version.
Class Method Summary collapse
Instance Method Summary collapse
- #changed? ⇒ Boolean
-
#initialize(repository_root:, revision:, ruby_version:, target_ruby_version:, rails_version:, analyzers:, analyzer_versions:, configuration_mode:, configuration_digest:, deterministic_inputs:, git_context: nil) ⇒ RunContext
constructor
A new instance of RunContext.
Constructor Details
#initialize(repository_root:, revision:, ruby_version:, target_ruby_version:, rails_version:, analyzers:, analyzer_versions:, configuration_mode:, configuration_digest:, deterministic_inputs:, git_context: nil) ⇒ RunContext
Returns a new instance of RunContext.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rail_verdict/run_context.rb', line 57 def initialize(repository_root:, revision:, ruby_version:, target_ruby_version:, rails_version:, analyzers:, analyzer_versions:, configuration_mode:, configuration_digest:, deterministic_inputs:, git_context: nil) @repository_root = repository_root.dup.freeze @revision = revision && revision.dup.freeze @ruby_version = ruby_version.dup.freeze @target_ruby_version = target_ruby_version && target_ruby_version.dup.freeze @rails_version = rails_version && rails_version.dup.freeze @analyzers = deep_freeze(analyzers) @analyzer_versions = deep_freeze(analyzer_versions) @configuration_mode = configuration_mode.dup.freeze @configuration_digest = configuration_digest.dup.freeze @deterministic_inputs = deep_freeze(deterministic_inputs.dup) @git_context = git_context freeze end |
Instance Attribute Details
#analyzer_versions ⇒ Object (readonly)
Returns the value of attribute analyzer_versions.
14 15 16 |
# File 'lib/rail_verdict/run_context.rb', line 14 def analyzer_versions @analyzer_versions end |
#analyzers ⇒ Object (readonly)
Returns the value of attribute analyzers.
14 15 16 |
# File 'lib/rail_verdict/run_context.rb', line 14 def analyzers @analyzers end |
#configuration_digest ⇒ Object (readonly)
Returns the value of attribute configuration_digest.
14 15 16 |
# File 'lib/rail_verdict/run_context.rb', line 14 def configuration_digest @configuration_digest end |
#configuration_mode ⇒ Object (readonly)
Returns the value of attribute configuration_mode.
14 15 16 |
# File 'lib/rail_verdict/run_context.rb', line 14 def configuration_mode @configuration_mode end |
#deterministic_inputs ⇒ Object (readonly)
Returns the value of attribute deterministic_inputs.
14 15 16 |
# File 'lib/rail_verdict/run_context.rb', line 14 def deterministic_inputs @deterministic_inputs end |
#git_context ⇒ Object (readonly)
Returns the value of attribute git_context.
14 15 16 |
# File 'lib/rail_verdict/run_context.rb', line 14 def git_context @git_context end |
#rails_version ⇒ Object (readonly)
Returns the value of attribute rails_version.
14 15 16 |
# File 'lib/rail_verdict/run_context.rb', line 14 def rails_version @rails_version end |
#repository_root ⇒ Object (readonly)
Returns the value of attribute repository_root.
14 15 16 |
# File 'lib/rail_verdict/run_context.rb', line 14 def repository_root @repository_root end |
#revision ⇒ Object (readonly)
Returns the value of attribute revision.
14 15 16 |
# File 'lib/rail_verdict/run_context.rb', line 14 def revision @revision end |
#ruby_version ⇒ Object (readonly)
Returns the value of attribute ruby_version.
14 15 16 |
# File 'lib/rail_verdict/run_context.rb', line 14 def ruby_version @ruby_version end |
#target_ruby_version ⇒ Object (readonly)
Returns the value of attribute target_ruby_version.
14 15 16 |
# File 'lib/rail_verdict/run_context.rb', line 14 def target_ruby_version @target_ruby_version end |
Class Method Details
.build(repository_root:, configuration:, analyzer_versions:, revision_resolver: nil, git_context: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rail_verdict/run_context.rb', line 18 def self.build(repository_root:, configuration:, analyzer_versions:, revision_resolver: nil, git_context: nil) root = begin File.realpath(repository_root) rescue Errno::ENOENT, Errno::EACCES raise RailVerdict::Error, "repository root does not exist: #{repository_root}" end raise RailVerdict::Error, "repository root is not a directory: #{repository_root}" unless File.directory?(root) revision = revision_resolver ? revision_resolver.call(root) : nil lockfile_text = read_lockfile(root) new( repository_root: root, revision: revision, ruby_version: RUBY_VERSION, target_ruby_version: lockfile_text && lockfile_text[GEMFILE_LOCK_RUBY, 1], rails_version: lockfile_text && lockfile_text[GEMFILE_LOCK_RAILS, 1], analyzers: configuration.analyzers, analyzer_versions: analyzer_versions, configuration_mode: configuration.mode, configuration_digest: configuration.digest, deterministic_inputs: DETERMINISTIC_INPUTS, git_context: git_context ) end |
Instance Method Details
#changed? ⇒ Boolean
74 75 76 |
# File 'lib/rail_verdict/run_context.rb', line 74 def changed? !@git_context.nil? end |