Class: IRuby::Dependencies

Inherits:
Object
  • Object
show all
Defined in:
lib/iruby/dependencies.rb,
lib/iruby/dependencies/version.rb

Constant Summary collapse

VERSION =
"3.0.3"

Instance Method Summary collapse

Constructor Details

#initialize(config, verbose: false, &block) ⇒ Dependencies

Returns a new instance of Dependencies.



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

def initialize config, verbose: false, &block
  @config = config
  @verbose = verbose 

  instance_eval &block

  gemfile do 
    # tell bundler to use our gem sources
    Gem.sources.each {|source| source source.to_s}
    instance_eval &block
  end
end

Instance Method Details

#exec(string) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/iruby/dependencies.rb', line 26

def exec string
  stdout, stderr, exit_status = Open3.capture3(string)

  if exit_status.success?
    if @verbose 
      Bundler.ui.info stdout unless stdout.empty?
      Bundler.ui.warn stderr unless stderr.empty?
    end
  else
    puts stdout unless stdout.empty?
    warn stderr unless stderr.empty?
    raise "\"exec '#{string}'\" failed on dependency installation"
  end
end

#gem(name, *args) ⇒ Object



20
21
22
23
24
# File 'lib/iruby/dependencies.rb', line 20

def gem name, *args
  if commands = @config[name]
    commands.each {|command| send *command}
  end
end

#source(*args, &block) ⇒ Object

gemfiles allow specifying alternate sources for gems make sure we check the block for gems in those sources



43
44
45
# File 'lib/iruby/dependencies.rb', line 43

def source *args, &block
  instance_eval &block if block_given?
end

#to_htmlObject



47
48
49
50
51
52
53
54
55
# File 'lib/iruby/dependencies.rb', line 47

def to_html
  <<-HTML
    <div style='background: rgba(0,255,0,0.3);
                font-family: monospace;
                padding: 5px;'>
      <b>Dependencies successfully installed!</b>
    </div>
  HTML
end