Sha256: 158f94d46a079f8da05e4152cf9745b09663180bc5a45866fa39bb1610f035bc

Contents?: true

Size: 1.18 KB

Versions: 28

Compression:

Stored size: 1.18 KB

Contents

module Cornucopia
  module Util
    # This is a stupid little settings class
    # Basicaly, anything you send to it is put into a hash or returned from a hash.
    class GenericSettings
      def initialize
        @settings_hash = {}
      end

      def method_missing(method_sym, *arguments, &block)
        if self.respond_to?("super__#{method_sym}".to_sym)
          super
        else
          if method_sym.to_s[-1] == "="
            raise "wrong number of arguments (#{arguments.length} for 1)" if !arguments || arguments.length != 1
            raise "block not accepted" if block

            @settings_hash[method_sym.to_s[0..-2].to_sym] = arguments[0]
          else
            raise "too many arguments (#{arguments.length} for 0)" if arguments && arguments.length > 0
            raise "block not accepted" if block
            @settings_hash[method_sym]
          end
        end
      end

      def respond_to?(method_sym, include_private = false)
        method_name = method_sym.to_s
        if method_name[0.."super__".length - 1] == "super__"
          super(method_sym["super__".length..-1].to_sym, include_private)
        else
          true
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
cornucopia-0.1.40 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.39 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.38 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.37 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.36 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.35 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.34 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.33 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.32 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.31 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.30 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.29 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.28 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.26 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.25 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.24 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.23 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.22 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.21 lib/cornucopia/util/generic_settings.rb
cornucopia-0.1.20 lib/cornucopia/util/generic_settings.rb