| Class | SOAP::Property |
| In: |
soap/property.rb
|
| Parent: | Object |
Property stream format:
line separator is \r?\n. 1 line per a property.
line which begins with '#' is a comment line. empty line is ignored, too.
key/value separator is ':' or '='.
'\' as escape character. but line separator cannot be escaped.
\s at the head/tail of key/value are trimmed.
'[' + key + ']' indicates property section. for example,
[aaa.bbb]
ccc = ddd
eee.fff = ggg
[]
aaa.hhh = iii
is the same as;
aaa.bbb.ccc = ddd
aaa.bbb.eee.fff = ggg
aaa.hhh = iii
| FrozenError | = | (RUBY_VERSION >= "1.9.0") ? RuntimeError : TypeError |
| KEY_REGSRC | = | '([^=:\\\\]*(?:\\\\.[^=:\\\\]*)*)' |
| DEF_REGSRC | = | '\\s*' + KEY_REGSRC + '\\s*[=:]\\s*(.*)' |
| COMMENT_REGEXP | = | Regexp.new('^(?:#.*|)$') |
| CATDEF_REGEXP | = | Regexp.new("^\\[\\s*#{KEY_REGSRC}\\s*\\]$") |
| LINE_REGEXP | = | Regexp.new("^#{DEF_REGSRC}$") |
| NO_HOOK | = | [].freeze |
# File soap/property.rb, line 59 def initialize @store = Hash.new @hook = Hash.new @self_hook = Array.new @locked = false end
name: a Symbol, String or an Array
# File soap/property.rb, line 105 def [](name) referent(name_to_a(name)) end
name: a Symbol, String or an Array; nil means hook to the root cascade: true/false; for cascading hook of sub key hook: block which will be called with 2 args, name and value
# File soap/property.rb, line 129 def add_hook(name = nil, cascade = false, &hook) if name == nil or name == true or name == false cascade = name assign_self_hook(cascade, &hook) else assign_hook(name_to_a(name), cascade, &hook) end end
# File soap/property.rb, line 71 def load(stream) key_prefix = "" stream.each_with_index do |line, lineno| line.sub!(/\r?\n\z/, '') case line when COMMENT_REGEXP next when CATDEF_REGEXP key_prefix = $1.strip when LINE_REGEXP key, value = $1.strip, $2.strip key = "#{key_prefix}.#{key}" unless key_prefix.empty? key, value = loadstr(key), loadstr(value) self[key] = value else raise TypeError.new( "property format error at line #{lineno + 1}: `#{line}'") end end self end
find property from $:.
# File soap/property.rb, line 94 def loadproperty(propname) return loadpropertyfile(propname) if File.file?(propname) $:.each do |path| if File.file?(file = File.join(path, propname)) return loadpropertyfile(file) end end nil end
# File soap/property.rb, line 156 def lock(cascade = false) if cascade each_key do |key| key.lock(cascade) end end @locked = true self end
# File soap/property.rb, line 166 def unlock(cascade = false) @locked = false if cascade each_key do |key| key.unlock(cascade) end end self end
# File soap/property.rb, line 182 def deref_key(key) check_lock(key) ref = @store[key] ||= self.class.new unless propkey?(ref) raise ArgumentError.new("key `#{key}' already defined as a value") end ref end
# File soap/property.rb, line 199 def local_assign(key, value) check_lock(key) if @locked if propkey?(value) raise FrozenError.new("cannot add any key to locked property") elsif propkey?(@store[key]) raise FrozenError.new("cannot override any key in locked property") end end @store[key] = value end
# File soap/property.rb, line 219 def local_assign_hook(key, cascade, &hook) check_lock(key) @store[key] ||= nil (@hook[key] ||= []) << [hook, cascade] end
# File soap/property.rb, line 211 def local_hook(key, direct) hooks = [] (@self_hook + (@hook[key] || NO_HOOK)).each do |hook, cascade| hooks << hook if direct or cascade end hooks end
ruby-doc.org is hosted and maintained by James Britt and Happy Camper Studios, a Ruby application development company in Phoenix, Arizona. The site was created in 2002 as part of the Ruby Documentation Project to promote the Ruby language and to help other Ruby hackers.
Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.
For more information on the Ruby programming language, visit ruby-lang.org.
Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.