Sha256: e0d6412909a6c350aa6de1addcdb072fc1a0e9118313781621c0ca4a743e8665

Contents?: true

Size: 933 Bytes

Versions: 8

Compression:

Stored size: 933 Bytes

Contents

module MotionPrime
  class Config
    def initialize(attributes = {})
      @attributes = attributes || {}
    end

    def [](key)
      fetch(key.to_sym) || store(key, self.class.new)
    end

    def store(key, value)
      @attributes[key.to_sym] = value
    end
    alias :[]= :store

    def fetch(key)
      @attributes[key.to_sym]
    end

    def nil?
      @attributes.empty?
    end
    alias :blank? :nil?

    def has_key?(key)
      !self[key].is_a?(self.class)
    end

    class << self
      def method_missing(name, *args, &block)
        @base_config ||= self.new()
        @base_config.send(name.to_sym, *args, &block)
      end
    end

    def method_missing(name, *args, &block)
      if block_given?
        yield self[name]
      else
        name = name.to_s
        if /(.+)=$/.match(name)
          return store($1, args[0])
        else
          return self[name]
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
motion-prime-0.2.0 motion-prime/config/config.rb
motion-prime-0.1.7 motion-prime/config/config.rb
motion-prime-0.1.6 motion-prime/config/config.rb
motion-prime-0.1.5 motion-prime/config/config.rb
motion-prime-0.1.4 motion-prime/config/config.rb
motion-prime-0.1.3 motion-prime/config/config.rb
motion-prime-0.1.2 motion-prime/config/config.rb
motion-prime-0.1.1 motion-prime/config/config.rb