Class: Mud::Dependency

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#contextObject (readonly)

Returns the value of attribute context.



15
16
17
# File 'lib/mud/dependency.rb', line 15

def context
  @context
end

#nameObject (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

Returns:

  • (Boolean)


30
31
32
# File 'lib/mud/dependency.rb', line 30

def resolvable?
  !!resolve
end

#resolveObject

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_sObject



22
23
24
# File 'lib/mud/dependency.rb', line 22

def to_s
  "Mud::Dependency #{@name}"
end