Class: Mud::Dependency
- Inherits:
-
Object
- Object
- Mud::Dependency
- Defined in:
- lib/mud/dependency.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name, context) ⇒ Dependency
constructor
A new instance of Dependency.
- #resolvable? ⇒ Boolean
-
#resolve ⇒ Object
Resolves to the corresponding module if present in this context.
- #to_s ⇒ Object
Constructor Details
#initialize(name, context) ⇒ Dependency
Returns a new instance of Dependency.
17 18 19 20 |
# File 'lib/mud/dependency.rb', line 17 def initialize(name, context) @name = name @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
15 16 17 |
# File 'lib/mud/dependency.rb', line 15 def context @context end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/mud/dependency.rb', line 15 def name @name end |
Class Method Details
.analyze(src, context) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/mud/dependency.rb', line 4 def self.analyze(src, context) dependencies = Set.new # Find all required files on the form require('name') og require('name', 'sub_name', ...) src.scan(/require\(((?:'[^']+'(?:,\s)?)+)\)/).each do |req| req.first.scan(/'([^']+)'/).each { |name| dependencies << new(name.first, context) } end dependencies.to_a end |
Instance Method Details
#==(other) ⇒ Object
26 27 28 |
# File 'lib/mud/dependency.rb', line 26 def ==(other) other.is_a?(self.class) and other.name == @name end |
#resolvable? ⇒ Boolean
30 31 32 |
# File 'lib/mud/dependency.rb', line 30 def resolvable? !!resolve end |
#resolve ⇒ Object
Resolves to the corresponding module if present in this context.
35 36 37 |
# File 'lib/mud/dependency.rb', line 35 def resolve @context.module(@name) end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/mud/dependency.rb', line 22 def to_s "Mud::Dependency #{@name}" end |