Class: ConfigTable

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/roebe/setup/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',
  '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

Methods included from Enumerable

#uniq_by

Constructor Details

#initialize(rbconfig) ⇒ ConfigTable

#

initialize

#


43
44
45
46
47
48
49
50
51
52
# File 'lib/roebe/setup/setup.rb', line 43

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.



55
56
57
# File 'lib/roebe/setup/setup.rb', line 55

def config_opt
  @config_opt
end

#install_prefixObject

Returns the value of attribute install_prefix.



54
55
56
# File 'lib/roebe/setup/setup.rb', line 54

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.



57
58
59
# File 'lib/roebe/setup/setup.rb', line 57

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.



58
59
60
# File 'lib/roebe/setup/setup.rb', line 58

def verbose=(value)
  @verbose = value
end

Instance Method Details

#[](key) ⇒ Object

#

[]

#


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

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

#[]=(key, val) ⇒ Object

#

[]=

#


84
85
86
# File 'lib/roebe/setup/setup.rb', line 84

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

#add(item) ⇒ Object

#

add

#


119
120
121
122
# File 'lib/roebe/setup/setup.rb', line 119

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

#dllextObject



365
366
367
# File 'lib/roebe/setup/setup.rb', line 365

def dllext
  @rbconfig['DLEXT']
end

#each(&block) ⇒ Object

#

each

#


98
99
100
# File 'lib/roebe/setup/setup.rb', line 98

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

#fixupObject

#

fixup

#


348
349
350
351
352
353
354
355
# File 'lib/roebe/setup/setup.rb', line 348

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

#key?(i) ⇒ Boolean

#

key?

#

Returns:

  • (Boolean)


105
106
107
# File 'lib/roebe/setup/setup.rb', line 105

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

#load_multipackage_entriesObject

#

load_multipackage_entries

#


308
309
310
311
312
# File 'lib/roebe/setup/setup.rb', line 308

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

#load_savefileObject

#

load_savefile

#


153
154
155
156
157
158
159
160
161
162
# File 'lib/roebe/setup/setup.rb', line 153

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

#load_script(path, inst = nil) ⇒ Object

#

load_script

#


137
138
139
140
141
# File 'lib/roebe/setup/setup.rb', line 137

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

#

load_standard_entries

#


179
180
181
182
183
# File 'lib/roebe/setup/setup.rb', line 179

def load_standard_entries
  standard_entries(@rbconfig).each {|entry|
    add entry
  }
end

#lookup(name) ⇒ Object

#

lookup

#


112
113
114
# File 'lib/roebe/setup/setup.rb', line 112

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

#namesObject

#

names

#


91
92
93
# File 'lib/roebe/setup/setup.rb', line 91

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

#no_harm?Boolean

#

no_harm?

#

Returns:

  • (Boolean)


70
71
72
# File 'lib/roebe/setup/setup.rb', line 70

def no_harm?
  @no_harm
end

#parse_opt(opt) ⇒ Object

#

parse_opt

#


360
361
362
363
# File 'lib/roebe/setup/setup.rb', line 360

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

#

remove

#


127
128
129
130
131
132
# File 'lib/roebe/setup/setup.rb', line 127

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

#saveObject

#

save (save tag)

#


167
168
169
170
171
172
173
174
# File 'lib/roebe/setup/setup.rb', line 167

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

#savefileObject

#

savefile

#


146
147
148
# File 'lib/roebe/setup/setup.rb', line 146

def savefile
  '.config'
end

#value_config?(name) ⇒ Boolean

Returns:

  • (Boolean)


369
370
371
# File 'lib/roebe/setup/setup.rb', line 369

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

#verbose?Boolean

#

verbose?

#

Returns:

  • (Boolean)


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

def verbose?
  @verbose
end