Class: Dep::Dependency
- Inherits:
-
Object
- Object
- Dep::Dependency
- Defined in:
- lib/dependencies/dep.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #for_environment?(env) ⇒ Boolean
-
#initialize(name, version = nil, environment = nil, url = nil) ⇒ Dependency
constructor
A new instance of Dependency.
- #require ⇒ Object
- #require_gem ⇒ Object
- #require_vendor ⇒ Object
- #to_s ⇒ Object
- #vendor_name ⇒ Object
- #vendor_path ⇒ Object
- #version_number ⇒ Object
Constructor Details
#initialize(name, version = nil, environment = nil, url = nil) ⇒ Dependency
Returns a new instance of Dependency.
8 9 10 11 12 13 |
# File 'lib/dependencies/dep.rb', line 8 def initialize(name, version = nil, environment = nil, url = nil) @name = name @version = version if version && !version.empty? @environment = environment ? environment.split(/\, ?/) : [] @url = url end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
5 6 7 |
# File 'lib/dependencies/dep.rb', line 5 def environment @environment end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/dependencies/dep.rb', line 3 def name @name end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/dependencies/dep.rb', line 6 def url @url end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
4 5 6 |
# File 'lib/dependencies/dep.rb', line 4 def version @version end |
Instance Method Details
#for_environment?(env) ⇒ Boolean
15 16 17 |
# File 'lib/dependencies/dep.rb', line 15 def for_environment?(env) environment.empty? || environment.include?(env) end |
#require ⇒ Object
48 49 50 |
# File 'lib/dependencies/dep.rb', line 48 def require require_vendor || require_gem end |
#require_gem ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/dependencies/dep.rb', line 37 def require_gem return unless defined?(Gem) begin gem(*[name, version].compact) true rescue Gem::LoadError => e false end end |
#require_vendor ⇒ Object
33 34 35 |
# File 'lib/dependencies/dep.rb', line 33 def require_vendor $:.unshift(File.(vendor_path)) if vendor_path end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/dependencies/dep.rb', line 52 def to_s [name, version, ("(#{environment.join(", ")})" unless environment.empty?)].compact.join(" ") end |
#vendor_name ⇒ Object
23 24 25 |
# File 'lib/dependencies/dep.rb', line 23 def vendor_name version ? "#{name}-#{version_number}" : name end |
#vendor_path ⇒ Object
27 28 29 30 31 |
# File 'lib/dependencies/dep.rb', line 27 def vendor_path Dir[File.join("vendor", vendor_name, "lib")].first || Dir[File.join("vendor", "#{vendor_name}*", "lib")].first || Dir[File.join("vendor", name, "lib")].first end |
#version_number ⇒ Object
19 20 21 |
# File 'lib/dependencies/dep.rb', line 19 def version_number version[/([\d\.]+)$/, 1] end |