Class: Yoda::Commands::Setup

Inherits:
Base
  • Object
show all
Defined in:
lib/yoda/commands/setup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

run

Constructor Details

#initialize(dir: nil, force_build: false) ⇒ Setup

Returns a new instance of Setup.

Parameters:

  • dir (String) (defaults to: nil)


16
17
18
19
20
# File 'lib/yoda/commands/setup.rb', line 16

def initialize(dir: nil, force_build: false)
  @dir = dir || Dir.pwd
  @force_build = force_build
  @bars = {}
end

Instance Attribute Details

#barsHash{ Symbol => ProgressBar } (readonly)

Returns:

  • (Hash{ Symbol => ProgressBar })


13
14
15
# File 'lib/yoda/commands/setup.rb', line 13

def bars
  @bars
end

#dirString (readonly)

Returns:

  • (String)


7
8
9
# File 'lib/yoda/commands/setup.rb', line 7

def dir
  @dir
end

#force_buildtrue, false (readonly)

Returns:

  • (true, false)


10
11
12
# File 'lib/yoda/commands/setup.rb', line 10

def force_build
  @force_build
end

Instance Method Details

#projectObject



34
35
36
# File 'lib/yoda/commands/setup.rb', line 34

def project
  @project ||= Store::Project.new(dir)
end

#runObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/yoda/commands/setup.rb', line 22

def run
  build_core_index
  if File.exist?(File.expand_path('Gemfile.lock', dir)) || force_build
    Logger.info 'Building index for the current project...'
    Instrument.instance.hear(initialization_progress: method(:on_progress), registry_dump: method(:on_progress)) do
      force_build ? project.rebuild_cache : project.build_cache
    end
  else
    Logger.info 'Skipped building project index because Gemfile.lock is not exist for the current dir'
  end
end