Class: Bundler::Dependency

Inherits:
Gem::Dependency show all
Defined in:
lib/bowline/bundler/dependency.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Gem::Dependency

#required_by

Constructor Details

#initialize(name, options = {}, &block) ⇒ Dependency

Returns a new instance of Dependency.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bowline/bundler/dependency.rb', line 8

def initialize(name, options = {}, &block)
  options.dup.each do |key, value|
    options[key.to_s] = options.delete(key)
  end

  super(name, options["version"] || ">= 0")

  @require_as = options["require_as"]
  @only       = options["only"]
  @except     = options["except"]
  @source     = options["source"]
  @block      = block

  if (@only && @only.include?("rubygems")) || (@except && @except.include?("rubygems"))
    raise InvalidEnvironmentName, "'rubygems' is not a valid environment name"
  end
end

Instance Attribute Details

#exceptObject (readonly)

Returns the value of attribute except.



5
6
7
# File 'lib/bowline/bundler/dependency.rb', line 5

def except
  @except
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/bowline/bundler/dependency.rb', line 5

def name
  @name
end

#onlyObject (readonly)

Returns the value of attribute only.



5
6
7
# File 'lib/bowline/bundler/dependency.rb', line 5

def only
  @only
end

#require_asObject (readonly)

Returns the value of attribute require_as.



5
6
7
# File 'lib/bowline/bundler/dependency.rb', line 5

def require_as
  @require_as
end

#sourceObject

Returns the value of attribute source.



6
7
8
# File 'lib/bowline/bundler/dependency.rb', line 6

def source
  @source
end

Instance Method Details

#==(o) ⇒ Object



54
55
56
57
# File 'lib/bowline/bundler/dependency.rb', line 54

def ==(o)
  [name, version, require_as, only, except] ==
    [o.name, o.version, o.require_as, o.only, o.except]
end

#in?(environment) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# File 'lib/bowline/bundler/dependency.rb', line 26

def in?(environment)
  environment = environment.to_s

  return false unless !@only || @only.include?(environment)
  return false if @except && @except.include?(environment)
  true
end

#no_bundle?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/bowline/bundler/dependency.rb', line 50

def no_bundle?
  source == SystemGemSource.instance
end

#require_env(environment) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bowline/bundler/dependency.rb', line 34

def require_env(environment)
  return unless in?(environment)

  if @require_as
    Array(@require_as).each { |file| require file }
  else
    begin
      require name
    rescue LoadError
      # Do nothing
    end
  end

  @block.call if @block
end