Class: ConfigTable

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/gems/xmpp4r-0.4/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

Methods included from Enumerable

#reject, #sort_by

Constructor Details

#initialize(rbconfig) ⇒ ConfigTable

Returns a new instance of ConfigTable.



50
51
52
53
54
55
56
57
58
59
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 50

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.



62
63
64
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 62

def config_opt
  @config_opt
end

#install_prefixObject

Returns the value of attribute install_prefix.



61
62
63
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 61

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.



70
71
72
# File 'lib/gems/xmpp4r-0.4/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/gems/xmpp4r-0.4/setup.rb', line 64

def verbose=(value)
  @verbose = value
end

Instance Method Details

#[](key) ⇒ Object



76
77
78
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 76

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

#[]=(key, val) ⇒ Object



80
81
82
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 80

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

#add(item) ⇒ Object



100
101
102
103
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 100

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

#dllextObject



310
311
312
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 310

def dllext
  @rbconfig['DLEXT']
end

#each(&block) ⇒ Object



88
89
90
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 88

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

#fixupObject



296
297
298
299
300
301
302
303
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 296

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)


92
93
94
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 92

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

#load_multipackage_entriesObject



261
262
263
264
265
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 261

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

#load_savefileObject



122
123
124
125
126
127
128
129
130
131
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 122

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



112
113
114
115
116
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 112

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



142
143
144
145
146
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 142

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

#lookup(name) ⇒ Object



96
97
98
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 96

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

#namesObject



84
85
86
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 84

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

#no_harm?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 72

def no_harm?
  @no_harm
end

#parse_opt(opt) ⇒ Object



305
306
307
308
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 305

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



105
106
107
108
109
110
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 105

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

#saveObject



133
134
135
136
137
138
139
140
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 133

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



118
119
120
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 118

def savefile
  '.config'
end

#value_config?(name) ⇒ Boolean

Returns:

  • (Boolean)


314
315
316
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 314

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

#verbose?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/gems/xmpp4r-0.4/setup.rb', line 66

def verbose?
  @verbose
end