Class: Safedep::Runner
- Inherits:
-
Object
- Object
- Safedep::Runner
- Defined in:
- lib/safedep/runner.rb
Constant Summary collapse
- GEMFILE_PATH =
'Gemfile'.freeze
- GEMFILE_LOCK_PATH =
'Gemfile.lock'.freeze
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
- #check_file_existence!(path, additional_message = nil) ⇒ Object
- #dependencies ⇒ Object
- #gemfile ⇒ Object
- #gemfile_lock ⇒ Object
- #gemfiles ⇒ Object
- #gemspec ⇒ Object
-
#initialize(configuration = Configuration.new) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
- #should_ignore?(dependency) ⇒ Boolean
- #validate! ⇒ Object
- #version_specifiers(version) ⇒ Object
Constructor Details
#initialize(configuration = Configuration.new) ⇒ Runner
Returns a new instance of Runner.
14 15 16 |
# File 'lib/safedep/runner.rb', line 14 def initialize(configuration = Configuration.new) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
12 13 14 |
# File 'lib/safedep/runner.rb', line 12 def configuration @configuration end |
Instance Method Details
#check_file_existence!(path, additional_message = nil) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/safedep/runner.rb', line 71 def check_file_existence!(path, = nil) return if File.exist?(path) = "#{path} is not found." << ' ' + if fail Error, end |
#dependencies ⇒ Object
42 43 44 |
# File 'lib/safedep/runner.rb', line 42 def dependencies @dependencies ||= gemfiles.map(&:dependencies).reduce(:+) end |
#gemfile ⇒ Object
57 58 59 60 61 62 |
# File 'lib/safedep/runner.rb', line 57 def gemfile @gemfile ||= begin check_file_existence!(GEMFILE_PATH) Gemologist::Gemfile.new(GEMFILE_PATH) end end |
#gemfile_lock ⇒ Object
64 65 66 67 68 69 |
# File 'lib/safedep/runner.rb', line 64 def gemfile_lock @gemfile_lock ||= begin check_file_existence!(GEMFILE_LOCK_PATH, 'Please run `bundle install`.') Safedep::GemfileLock.new(GEMFILE_LOCK_PATH) end end |
#gemfiles ⇒ Object
46 47 48 |
# File 'lib/safedep/runner.rb', line 46 def gemfiles @gemfiles ||= [gemspec, gemfile].compact end |
#gemspec ⇒ Object
50 51 52 53 54 55 |
# File 'lib/safedep/runner.rb', line 50 def gemspec @gemspec ||= begin path = Dir['*.gemspec'].first Gemologist::Gemspec.new(path) if path end end |
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/safedep/runner.rb', line 18 def run validate! dependencies.each do |dep| next if should_ignore?(dep) lockfile_dep = gemfile_lock.find_dependency(dep.name) unless lockfile_dep fail Error, "#{dep.name.inspect} definition is not found in #{gemfile_lock.path}. " \ 'Please run `bundle install`.' end dep.version_specifiers = version_specifiers(lockfile_dep.version) end gemfiles.each(&:rewrite!) end |
#should_ignore?(dependency) ⇒ Boolean
78 79 80 81 82 |
# File 'lib/safedep/runner.rb', line 78 def should_ignore?(dependency) return true unless dependency.version_specifiers.empty? return true unless (dependency.groups & configuration.skipped_groups).empty? [:git, :github, :path].any? { |key| dependency.[key] } end |
#validate! ⇒ Object
37 38 39 40 |
# File 'lib/safedep/runner.rb', line 37 def validate! gemfile_lock gemfile end |
#version_specifiers(version) ⇒ Object
84 85 86 |
# File 'lib/safedep/runner.rb', line 84 def version_specifiers(version) Policy::SemVer.version_specifiers(version) end |