Sha256: 40429a42acb7c2db4cc7b781275867f4cddf324de962d25f0ba5bc2a678f7ab9

Contents?: true

Size: 829 Bytes

Versions: 1

Compression:

Stored size: 829 Bytes

Contents

require "singleton"

module Workforce
  class Config
    include Singleton
    
    def self.config_attr(attr_name)
      define_method(attr_name) do |*args|
        raise ArgumentError, "wrong number of arguments (#{args.size} for 1)" if args.size > 1
        
        if instance_variable_get("@#{attr_name}").nil? || args[0]
          instance_variable_set("@#{attr_name}", args[0] || yield)
        end
        
        instance_variable_get("@#{attr_name}")
      end
    end
    
    def self.get(attr_name)
      self.instance.send(attr_name)
    end
    
    def initialize
      yield self if block_given?
    end
    
    def load_file(file_path)
      instance_eval(File.read(file_path), file_path)
    end

    config_attr :pid_dir do
      "./pid"
    end

    config_attr :log_dir do
      "./log"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workforce-0.1.1 lib/workforce/configuration.rb