Class: LazyPP::Package

Inherits:
Object show all
Defined in:
lib/readable-cpp/package.rb

Constant Summary collapse

PackageDir =
[
File.expand_path('~/.config/cpptranny/pkg'),
Dir.pwd]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Package

Returns a new instance of Package.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/readable-cpp/package.rb', line 21

def initialize name
  if f = find_pkg( name)
    @name = name
    dat = YAML.load_file f
    @includes = dat['include'].nil? ? nil : Array.wrap(dat['include'])
    @linker   = parse_sh(dat['linker'] || '')
    @compile_opts = parse_sh(dat['compile_opts'] || '')
    @flags = Array.wrap(dat['flags'] || nil).compact
  else
    abort "Could not find package #{name}. Searched in #{PackageDir.join', '}"
  end
end

Instance Attribute Details

#compile_optsObject (readonly)

Returns the value of attribute compile_opts.



15
16
17
# File 'lib/readable-cpp/package.rb', line 15

def compile_opts
  @compile_opts
end

#includesObject (readonly)

Returns the value of attribute includes.



15
16
17
# File 'lib/readable-cpp/package.rb', line 15

def includes
  @includes
end

#linkerObject (readonly)

Returns the value of attribute linker.



15
16
17
# File 'lib/readable-cpp/package.rb', line 15

def linker
  @linker
end

#nameObject (readonly) Also known as: to_s

Returns the value of attribute name.



15
16
17
# File 'lib/readable-cpp/package.rb', line 15

def name
  @name
end

Class Method Details

.new(name) ⇒ Object



16
17
18
19
# File 'lib/readable-cpp/package.rb', line 16

def self.new name
  name = Array.wrap(name).map(&:downcase).join(?/)
  @packages[name] ||= super(name)
end

Instance Method Details

#cpp0x?Boolean

Returns:

  • (Boolean)


42
# File 'lib/readable-cpp/package.rb', line 42

def cpp0x?() @flags.include?('c++0x') || @flags.include?('cpp0x') end

#find_pkg(name) ⇒ Object



44
45
46
47
48
49
# File 'lib/readable-cpp/package.rb', line 44

def find_pkg name
  n = name + '.yml'
  PackageDir.map(&File.margs(:join, n)).
  #PackageDir.map{ |d| File.join(d, n) }.
    detect(&File.method(:exists?)) 
end

#parse_sh(txt) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/readable-cpp/package.rb', line 34

def parse_sh txt
  if txt.respond_to? :map then txt.map { |t| parse_sh t }
  elsif txt =~ /^`(.+)`/ then 
    warn "Executing sh commands from package #{name}: `#$1`"
    %x{#$1}.chomp##.gsub(/-l\\?;(?<foo>[^\\;]+)\\?;/, '-l\k<foo>') ##<- temporary fix for pkg-config returning -L;/path/; 
  else txt end
end