Class: RQR::ConfigTable

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rqr.rb

Defined Under Namespace

Classes: BoolItem, ExecItem, Item, MetaConfigEnvironment, PackageSelectionItem, PathItem, ProgramItem, SelectItem

Constant Summary collapse

ALIASES =
{
  'std-ruby'         => 'librubyver',
  'stdruby'          => 'librubyver',
  'rubylibdir'       => 'librubyver',
  'archdir'          => 'librubyverarch',
  'site-ruby-common' => 'siteruby',     # For backward compatibility
  'site-ruby'        => 'siterubyver',  # For backward compatibility
  'bin-dir'          => 'bindir',
  'bin-dir'          => 'bindir',
  'rb-dir'           => 'rbdir',
  'so-dir'           => 'sodir',
  'data-dir'         => 'datadir',
  'ruby-path'        => 'rubypath',
  'ruby-prog'        => 'rubyprog',
  'ruby'             => 'rubyprog',
  'make-prog'        => 'makeprog',
  'make'             => 'makeprog'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rbconfig) ⇒ ConfigTable

Returns a new instance of ConfigTable.



51
52
53
54
55
56
57
58
59
60
# File 'lib/rqr.rb', line 51

def initialize(rbconfig)
  @rbconfig = rbconfig
  @items = []
  @table = {}
  # options
  @install_prefix = nil
  @config_opt = nil
  @verbose = true
  @no_harm = false
end

Instance Attribute Details

#config_optObject

Returns the value of attribute config_opt.



63
64
65
# File 'lib/rqr.rb', line 63

def config_opt
  @config_opt
end

#install_prefixObject

Returns the value of attribute install_prefix.



62
63
64
# File 'lib/rqr.rb', line 62

def install_prefix
  @install_prefix
end

#no_harm=(value) ⇒ Object (writeonly)

Sets the attribute no_harm

Parameters:

  • value

    the value to set the attribute no_harm to.



71
72
73
# File 'lib/rqr.rb', line 71

def no_harm=(value)
  @no_harm = value
end

#verbose=(value) ⇒ Object (writeonly)

Sets the attribute verbose

Parameters:

  • value

    the value to set the attribute verbose to.



65
66
67
# File 'lib/rqr.rb', line 65

def verbose=(value)
  @verbose = value
end

Instance Method Details

#[](key) ⇒ Object



77
78
79
# File 'lib/rqr.rb', line 77

def [](key)
  lookup(key).resolve(self)
end

#[]=(key, val) ⇒ Object



81
82
83
# File 'lib/rqr.rb', line 81

def []=(key, val)
  lookup(key).set val
end

#add(item) ⇒ Object



101
102
103
104
# File 'lib/rqr.rb', line 101

def add(item)
  @items.push item
  @table[item.name] = item
end

#dllextObject



311
312
313
# File 'lib/rqr.rb', line 311

def dllext
  @rbconfig['DLEXT']
end

#each(&block) ⇒ Object



89
90
91
# File 'lib/rqr.rb', line 89

def each(&block)
  @items.each(&block)
end

#fixupObject



297
298
299
300
301
302
303
304
# File 'lib/rqr.rb', line 297

def fixup
  ALIASES.each do |ali, name|
    @table[ali] = @table[name]
  end
  @items.freeze
  @table.freeze
  @options_re = /\A--(#{@table.keys.join('|')})(?:=(.*))?\z/
end

#key?(name) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/rqr.rb', line 93

def key?(name)
  @table.key?(name)
end

#load_multipackage_entriesObject



262
263
264
265
266
# File 'lib/rqr.rb', line 262

def load_multipackage_entries
  multipackage_entries().each do |ent|
    add ent
  end
end

#load_savefileObject



123
124
125
126
127
128
129
130
131
132
# File 'lib/rqr.rb', line 123

def load_savefile
  begin
    File.foreach(savefile()) do |line|
      k, v = *line.split(/=/, 2)
      self[k] = v.strip
    end
  rescue Errno::ENOENT
    setup_rb_error $!.message + "\n#{File.basename($0)} config first"
  end
end

#load_script(path, inst = nil) ⇒ Object



113
114
115
116
117
# File 'lib/rqr.rb', line 113

def load_script(path, inst = nil)
  if File.file?(path)
    MetaConfigEnvironment.new(self, inst).instance_eval File.read(path), path
  end
end

#load_standard_entriesObject



143
144
145
146
147
# File 'lib/rqr.rb', line 143

def load_standard_entries
  standard_entries(@rbconfig).each do |ent|
    add ent
  end
end

#lookup(name) ⇒ Object



97
98
99
# File 'lib/rqr.rb', line 97

def lookup(name)
  @table[name] or setup_rb_error "no such config item: #{name}"
end

#namesObject



85
86
87
# File 'lib/rqr.rb', line 85

def names
  @items.map {|i| i.name }
end

#no_harm?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/rqr.rb', line 73

def no_harm?
  @no_harm
end

#parse_opt(opt) ⇒ Object



306
307
308
309
# File 'lib/rqr.rb', line 306

def parse_opt(opt)
  m = @options_re.match(opt) or setup_rb_error "config: unknown option #{opt}"
  m.to_a[1,2]
end

#remove(name) ⇒ Object



106
107
108
109
110
111
# File 'lib/rqr.rb', line 106

def remove(name)
  item = lookup(name)
  @items.delete_if {|i| i.name == name }
  @table.delete_if {|name, i| i.name == name }
  item
end

#saveObject



134
135
136
137
138
139
140
141
# File 'lib/rqr.rb', line 134

def save
  @items.each {|i| i.value }
  File.open(savefile(), 'w') {|f|
    @items.each do |i|
      f.printf "%s=%s\n", i.name, i.value if i.value? and i.value
    end
  }
end

#savefileObject



119
120
121
# File 'lib/rqr.rb', line 119

def savefile
  '.config'
end

#value_config?(name) ⇒ Boolean

Returns:

  • (Boolean)


315
316
317
# File 'lib/rqr.rb', line 315

def value_config?(name)
  lookup(name).value?
end

#verbose?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/rqr.rb', line 67

def verbose?
  @verbose
end