Class: Freely::Dependency

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Dependency

Returns a new instance of Dependency.



8
9
10
11
12
# File 'lib/freely/dependency.rb', line 8

def initialize path
  @path = path
  @name = Tools.read_name path
  @dependencies = Tools.fyi(Dependency.from_path @path)
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



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

def dependencies
  @dependencies
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.from_path(path) ⇒ Object

Fetch dependencies from binary at path



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/freely/dependency.rb', line 15

def self.from_path path
  Tools.read_deps(path).split(/$/).map do |str|
    if \
        %r|\s(\S+)\s| =~ str \
        and not str.include? Options::SYSTEM_LIBS \
        and not str.include? Options::SYSTEM_FRAMEWORKS \
        and not str.include? path

      new $1 # construct dependency
    end
  end.compact
end

Instance Method Details

#to_sObject



38
39
40
# File 'lib/freely/dependency.rb', line 38

def to_s
  @name
end

#trackObject

Recursively read sub-dependencies



29
30
31
32
33
34
35
36
# File 'lib/freely/dependency.rb', line 29

def track
  unless @dependencies.empty?
    # sub-dependencies + me
    Tools.fyi(@dependencies.map!{|d| d.track}).push self
  else
    self # just me
  end
end