Class: ConfigTable

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/priority-queue/setup.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.



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/priority-queue/setup.rb', line 49

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

Instance Attribute Details

#config_optObject

Returns the value of attribute config_opt.



62
63
64
# File 'lib/priority-queue/setup.rb', line 62

def config_opt
  @config_opt
end

#install_prefixObject

Returns the value of attribute install_prefix.



61
62
63
# File 'lib/priority-queue/setup.rb', line 61

def install_prefix
  @install_prefix
end

#libsrc_patternObject

Returns the value of attribute libsrc_pattern.



76
77
78
# File 'lib/priority-queue/setup.rb', line 76

def libsrc_pattern
  @libsrc_pattern
end

#no_harm=(value) ⇒ Object (writeonly)

Sets the attribute no_harm

Parameters:

  • value

    the value to set the attribute no_harm to.



70
71
72
# File 'lib/priority-queue/setup.rb', line 70

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.



64
65
66
# File 'lib/priority-queue/setup.rb', line 64

def verbose=(value)
  @verbose = value
end

Instance Method Details

#[](key) ⇒ Object



78
79
80
# File 'lib/priority-queue/setup.rb', line 78

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

#[]=(key, val) ⇒ Object



82
83
84
# File 'lib/priority-queue/setup.rb', line 82

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

#add(item) ⇒ Object



102
103
104
105
# File 'lib/priority-queue/setup.rb', line 102

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

#dllextObject



312
313
314
# File 'lib/priority-queue/setup.rb', line 312

def dllext
  @rbconfig['DLEXT']
end

#each(&block) ⇒ Object



90
91
92
# File 'lib/priority-queue/setup.rb', line 90

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

#fixupObject



298
299
300
301
302
303
304
305
# File 'lib/priority-queue/setup.rb', line 298

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)


94
95
96
# File 'lib/priority-queue/setup.rb', line 94

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

#load_multipackage_entriesObject



263
264
265
266
267
# File 'lib/priority-queue/setup.rb', line 263

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

#load_savefileObject



124
125
126
127
128
129
130
131
132
133
# File 'lib/priority-queue/setup.rb', line 124

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



114
115
116
117
118
# File 'lib/priority-queue/setup.rb', line 114

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



144
145
146
147
148
# File 'lib/priority-queue/setup.rb', line 144

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

#lookup(name) ⇒ Object



98
99
100
# File 'lib/priority-queue/setup.rb', line 98

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

#namesObject



86
87
88
# File 'lib/priority-queue/setup.rb', line 86

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

#no_harm?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/priority-queue/setup.rb', line 72

def no_harm?
  @no_harm
end

#parse_opt(opt) ⇒ Object



307
308
309
310
# File 'lib/priority-queue/setup.rb', line 307

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



107
108
109
110
111
112
# File 'lib/priority-queue/setup.rb', line 107

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

#saveObject



135
136
137
138
139
140
141
142
# File 'lib/priority-queue/setup.rb', line 135

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



120
121
122
# File 'lib/priority-queue/setup.rb', line 120

def savefile
  '.config'
end

#value_config?(name) ⇒ Boolean

Returns:

  • (Boolean)


316
317
318
# File 'lib/priority-queue/setup.rb', line 316

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

#verbose?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/priority-queue/setup.rb', line 66

def verbose?
  @verbose
end