Method: Yap::World#initialize

Defined in:
lib/yap/world.rb

#initialize(addons:) ⇒ World

Returns a new instance of World.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/yap/world.rb', line 30

def initialize(addons:)
  @env = ENV.to_h.dup
  dom = build_editor_dom

  # ensure yap directory exists
  if !File.exists?(configuration.yap_path)
    puts
    puts yellow("Yap directory not found: #{configuration.yap_path}")
    puts
    puts "Initializing yap for the first time:"
    puts

    print "    Creating #{configuration.yap_path} "
    FileUtils.mkdir_p configuration.yap_path
    puts green("done")

    print "    Creating default #{configuration.preferred_yaprc_path} "
    FileUtils.cp configuration.yaprc_template_path, configuration.yap_path
    puts green("done")
    puts
    puts "To tweak yap take a look at #{configuration.preferred_yaprc_path}."
    puts
    puts "Reloading shell"
    reload!
  end

  @editor = RawLine::Editor.create(dom: dom)

  self.prompt = Yap::Shell::Prompt.new(text: DEFAULTS[:primary_prompt_text])
  self.secondary_prompt = Yap::Shell::Prompt.new(text: DEFAULTS[:secondary_prompt_text])

  @repl = Yap::Shell::Repl.new(world:self)

  @addons = addons.reduce(Hash.new) do |hsh, addon|
    hsh[addon.addon_name] = addon
    hsh
  end

  # initialize after they are all loaded in case they reference each other.
  addons.each { |addon| addon.initialize_world(self) }
end