SOAP::Property (Class)

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

Methods

<<   []   []=   add_hook   each   empty?   keys   load   load   loadproperty   lock   locked?   new   open   unlock   values  

Constants

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

Included Modules

Public Class methods

[Source]

# File soap/property.rb, line 37
  def self.load(stream)
    new.load(stream)
  end

find property from $:.

[Source]

# File soap/property.rb, line 46
  def self.loadproperty(propname)
    $:.each do |path|
      if File.file?(file = File.join(path, propname))
        return open(file)
      end
    end
    nil
  end

[Source]

# File soap/property.rb, line 55
  def initialize
    @store = Hash.new
    @hook = Hash.new
    @self_hook = Array.new
    @locked = false
  end

[Source]

# File soap/property.rb, line 41
  def self.open(filename)
    File.open(filename) { |f| load(f) }
  end

Public Instance methods

value: an Object key is generated by property

[Source]

# File soap/property.rb, line 108
  def <<(value)
    self[generate_new_key] = value
  end

name: a Symbol, String or an Array

[Source]

# File soap/property.rb, line 91
  def [](name)
    referent(name_to_a(name))
  end

name: a Symbol, String or an Array value: an Object

[Source]

# File soap/property.rb, line 97
  def []=(name, value)
    hooks = assign(name_to_a(name), value)
    normalized_name = normalize_name(name)
    hooks.each do |hook|
      hook.call(normalized_name, value)
    end
    value
  end

name: a Symbol, String or an Array. nil means hook to the root hook: block which will be called with 2 args, name and value

[Source]

# File soap/property.rb, line 114
  def add_hook(name = nil, &hook)
    if name.nil?
      assign_self_hook(&hook)
    else
      assign_hook(name_to_a(name), &hook)
    end
  end

[Source]

# File soap/property.rb, line 122
  def each
    @store.each do |key, value|
      yield(key, value)
    end
  end

[Source]

# File soap/property.rb, line 128
  def empty?
    @store.empty?
  end

[Source]

# File soap/property.rb, line 132
  def keys
    @store.keys
  end

[Source]

# File soap/property.rb, line 67
  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 = eval("\"#{key}\"")
        value = eval("\"#{value}\"")
        self[key] = value
      else
        raise TypeError.new(
          "property format error at line #{lineno + 1}: `#{line}'")
      end
    end
    self
  end

[Source]

# File soap/property.rb, line 140
  def lock(cascade = false)
    if cascade
      each_key do |key|
        key.lock(cascade)
      end
    end
    @locked = true
    self
  end

[Source]

# File soap/property.rb, line 160
  def locked?
    @locked
  end

[Source]

# File soap/property.rb, line 150
  def unlock(cascade = false)
    @locked = false
    if cascade
      each_key do |key|
        key.unlock(cascade)
      end
    end
    self
  end

[Source]

# File soap/property.rb, line 136
  def values
    @store.values
  end

[Validate]