Class: Ecogem::Workspace

Inherits:
Object
  • Object
show all
Defined in:
lib/ecogem/workspace.rb

Instance Method Summary collapse

Constructor Details

#initialize(args, options = {}, &block) ⇒ Workspace

Returns a new instance of Workspace.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ecogem/workspace.rb', line 7

def initialize(args, options = {}, &block)
  @args = args || ::Ecogem::Cli::Args.new([])
  options = {}.merge(options)
  new_tmpdir do |dir|
    begin
      @workdir = dir
      block.call self
      unless options[:readonly]
        gitsfile.save
      end
    end
  end
end

Instance Method Details

#envObject



25
26
27
# File 'lib/ecogem/workspace.rb', line 25

def env
  @env ||= ::Ecogem::Env.new(global_env, env_path)
end

#gemfileObject



46
47
48
# File 'lib/ecogem/workspace.rb', line 46

def gemfile
  @gemfile ||= ::Ecogem::Gemfile.new(gemfile_path)
end

#gitsfileObject



29
30
31
# File 'lib/ecogem/workspace.rb', line 29

def gitsfile
  @gitsfile ||= ::Ecogem::Gitsfile.new(nil, global_env.dir + '/gits/keys')
end

#global_envObject



21
22
23
# File 'lib/ecogem/workspace.rb', line 21

def global_env
  @global_env ||= ::Ecogem::Env.new(nil, ::File.expand_path(::Dir.home + '/.ecogem'))
end

#new_tmpdir(&block) ⇒ Object



58
59
60
61
62
63
# File 'lib/ecogem/workspace.rb', line 58

def new_tmpdir(&block)
  ::FileUtils.mkdir_p tmp_path unless ::File.exist?(tmp_path)
  ::Dir.mktmpdir(nil, tmp_path) do |dir|
    return block.call(dir)
  end
end