Class: Sunzi::Dependency

Inherits:
Struct
  • Object
show all
Defined in:
lib/sunzi/dependency.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Dependency

Returns a new instance of Dependency.



6
7
8
9
# File 'lib/sunzi/dependency.rb', line 6

def initialize(*args)
  super
  self.class.list[name] = self
end

Class Attribute Details

.listObject

Returns the value of attribute list.



12
13
14
# File 'lib/sunzi/dependency.rb', line 12

def list
  @list
end

Instance Attribute Details

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



2
3
4
# File 'lib/sunzi/dependency.rb', line 2

def name
  @name
end

#versionObject

Returns the value of attribute version

Returns:

  • (Object)

    the current value of version



2
3
4
# File 'lib/sunzi/dependency.rb', line 2

def version
  @version
end

Class Method Details

.load(key) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sunzi/dependency.rb', line 14

def load(key)
  unless dependency = @list[key]
    fail "#{key} is not initialized. Run Sunzi::Dependency.new('#{key}', '~> ...')"
  end

  name, version = dependency.name, dependency.version

  begin
    gem(name, version)
    require(name)
  rescue LoadError
    base = GemRoot.join('templates/dependency')
    which = if $!.to_s =~ /Gemfile/
      'gemfile'
    else
      'install'
    end
    text = ERB.new(base.join("#{which}.erb").read).result(binding)
    abort_with text
  end
end