Class: Rails::Hyperdrive::StackProfile
- Inherits:
-
Object
- Object
- Rails::Hyperdrive::StackProfile
- Defined in:
- lib/rails/hyperdrive/stack_profile.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
- .current ⇒ Object
- .default_lockfile_path ⇒ Object
- .from_lockfile(path, app_root: nil) ⇒ Object
- .reset! ⇒ Object
Instance Method Summary collapse
-
#initialize(path:, app_root: nil) ⇒ StackProfile
constructor
A new instance of StackProfile.
- #parse! ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(path:, app_root: nil) ⇒ StackProfile
Returns a new instance of StackProfile.
32 33 34 35 36 |
# File 'lib/rails/hyperdrive/stack_profile.rb', line 32 def initialize(path:, app_root: nil) @path = path @app_root = app_root @data = empty_profile end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
30 31 32 |
# File 'lib/rails/hyperdrive/stack_profile.rb', line 30 def data @data end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
30 31 32 |
# File 'lib/rails/hyperdrive/stack_profile.rb', line 30 def path @path end |
Class Method Details
.current ⇒ Object
9 10 11 |
# File 'lib/rails/hyperdrive/stack_profile.rb', line 9 def current @current ||= from_lockfile(default_lockfile_path) end |
.default_lockfile_path ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/rails/hyperdrive/stack_profile.rb', line 21 def default_lockfile_path if defined?(::Rails) && ::Rails.respond_to?(:root) && ::Rails.root ::Rails.root.join("Gemfile.lock").to_s else File.("Gemfile.lock", Dir.pwd) end end |
.from_lockfile(path, app_root: nil) ⇒ Object
17 18 19 |
# File 'lib/rails/hyperdrive/stack_profile.rb', line 17 def from_lockfile(path, app_root: nil) new(path: path, app_root: app_root).tap(&:parse!) end |
.reset! ⇒ Object
13 14 15 |
# File 'lib/rails/hyperdrive/stack_profile.rb', line 13 def reset! @current = nil end |
Instance Method Details
#parse! ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rails/hyperdrive/stack_profile.rb', line 38 def parse! unless File.exist?(@path) @data = empty_profile.merge(error: "Gemfile.lock not found at #{@path}") return self end contents = File.read(@path) parser = ::Bundler::LockfileParser.new(contents) specs = parser.specs.each_with_object({}) { |s, h| h[s.name] = s.version.to_s } @data = { rails: rails_info(specs), ruby: ruby_info(parser), database: database_info(specs), direct_dependencies: direct_dependencies(parser, specs), gem_skills: gem_skills_info } self end |
#to_h ⇒ Object
58 59 60 |
# File 'lib/rails/hyperdrive/stack_profile.rb', line 58 def to_h @data end |