Class: Freely::Tools

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

Class Method Summary collapse

Class Method Details

.check_file(path) ⇒ Object

Checks if file exist



19
20
21
22
23
24
# File 'lib/freely/tools.rb', line 19

def self.check_file path
  if not File.exist? path or File.directory? path
    STDERR.puts "File not found: #{path}"
    exit -1
  end
end

.fyi(array) ⇒ Object

Compact, flatten & unique



43
44
45
# File 'lib/freely/tools.rb', line 43

def self.fyi array
  array.compact.flatten.uniq {|e| e.name}
end

.is_lib?(name) ⇒ Boolean

Checks if given name seems to be library name

Returns:

  • (Boolean)


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

def self.is_lib? name
  name.end_with? '.dylib' or name.end_with? '.so'
end

.read_deps(path) ⇒ Object

Read dependencies from binary at path



7
8
9
10
# File 'lib/freely/tools.rb', line 7

def self.read_deps path
  check_file path
  `#{Options::VIEW_UTILITY} #{path}`
end

.read_name(path) ⇒ Object

Reads binary name from it’s path



27
28
29
30
31
32
33
34
35
# File 'lib/freely/tools.rb', line 27

def self.read_name path
  check_file path
  if %r|\S+/(\S+)$| =~ path
    $1
  else
    STDERR.puts "Unable to get binary name! (path was: #{path})"
    exit -1
  end
end

.replace_deps(path, old_dep, new_dep) ⇒ Object

Replace dependency in binary at path



13
14
15
16
# File 'lib/freely/tools.rb', line 13

def self.replace_deps path, old_dep, new_dep
  check_file path
  `#{Options::EDIT_UTILITY} #{old_dep} #{new_dep} #{path}`
end