Sha256: b7e8af055fc77e3dcc7bdd9fbd93c3d0c6ea8ed4dac0da09b3f49ddf920b5b5e

Contents?: true

Size: 1013 Bytes

Versions: 12

Compression:

Stored size: 1013 Bytes

Contents

#TODO: rdoc: this  defines methods on poolparty objects from a passed hash of options.
# For example, this is how instance.minimum_runtime is set.  See base.rb line 12 for example of default options that are added as methods in this way. 
module PoolParty
  module Configurable
    module ClassMethods      
      def default_options(h={})
        @default_options ||= h
      end
    end
    
    module InstanceMethods
      def options(h={})
        @options ||= self.class.default_options.merge(h)
      end
      
      def configure(h={})
        options(h).merge!(h)
      end
      
      def reconfigure(h={})
        @options = nil
        options(h)
      end
      
      def set_vars_from_options(opts={})
        opts.each {|k,v| self.send k.to_sym, send_if_method(v) } unless opts.empty?
      end
    end
    
    def self.included(receiver)
      receiver.extend         ClassMethods
      receiver.send :include, InstanceMethods
      receiver.send :include, MethodMissingSugar
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
auser-poolparty-0.2.81 lib/poolparty/modules/configurable.rb
auser-poolparty-0.2.84 lib/poolparty/modules/configurable.rb
auser-poolparty-0.2.85 lib/poolparty/modules/configurable.rb
auser-poolparty-0.2.88 lib/poolparty/modules/configurable.rb
auser-poolparty-0.2.89 lib/poolparty/modules/configurable.rb
auser-poolparty-0.2.90 lib/poolparty/modules/configurable.rb
auser-poolparty-0.2.91 lib/poolparty/modules/configurable.rb
auser-poolparty-0.2.92 lib/poolparty/modules/configurable.rb
auser-poolparty-0.2.93 lib/poolparty/modules/configurable.rb
auser-poolparty-0.2.94 lib/poolparty/modules/configurable.rb
auser-poolparty-1.0.0 lib/poolparty/modules/configurable.rb
poolparty-0.2.84 lib/poolparty/modules/configurable.rb