Sha256: 05f03ed50e3e584217d01091e3c99c02b46b22e695161fc520d2b9317b745e78

Contents?: true

Size: 712 Bytes

Versions: 12

Compression:

Stored size: 712 Bytes

Contents

module Netzke
  module Core
    # Allows deep-nested configuration without previously defining the hash tree:
    #
    #     config = Netzke::Core::OptionsHash.new
    #     config.basepack.grid_panel.add_form.with_tools = true
    #     config
    #     => {:basepack=>{:grid_panel=>{:add_form=>{:with_tools=>true}}}}
    class OptionsHash < ::Hash
      def []=(key, value)
        super(key.to_sym, value)
      end

      def [](key)
        super(key.to_sym)
      end

      def method_missing(name, *args)
        if name.to_s =~ /(.*)=$/
          self[$1.to_sym] = args.first
        else
          self.has_key?(name) ? self[name] : self[name] = OptionsHash.new
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
netzke-core-0.8.1 lib/netzke/core/options_hash.rb
netzke-core-0.8.0 lib/netzke/core/options_hash.rb
netzke-core-0.7.7 lib/netzke/core/options_hash.rb
netzke-core-0.7.6 lib/netzke/core/options_hash.rb
netzke-core-0.7.5 lib/netzke/core/options_hash.rb
netzke-core-0.7.4 lib/netzke/core/options_hash.rb
netzke-core-0.7.3 lib/netzke/core/options_hash.rb
netzke-core-0.7.2 lib/netzke/core/options_hash.rb
netzke-core-0.7.1 lib/netzke/core/options_hash.rb
netzke-core-0.6.7 lib/netzke/core/options_hash.rb
netzke-core-0.7.0 lib/netzke/core/options_hash.rb
netzke-core-0.6.6 lib/netzke/core/options_hash.rb