Module: ConfigSL::Collection

Included in:
Config
Defined in:
lib/configsl/collection.rb

Overview

Support options as collections.

This will format the values of the defined options when they are set on the config object. It will also format the values when they are retrieved, if they don't match their defined type.

The default behavior is to cast the value as the defined type. If the value is nil, it will be returned as is.

Examples:

Use the shorthand syntax to define a collection with no additional

options

class TestConfig < ConfigSL::Config
  include ConfigSL::Collection

  option :subarray, type: Array, collection: SubConfig
  option :subhash, type: Hash, collection: SubConfig
end

Automatically set a key on the collection members based on their

index (arrays) or keys (hashes), unless the key is already set

class TestConfig < ConfigSL::Config
  include ConfigSL::Collection

  option :subarray, type: Array, collection: { type: SubConfig, key: :index }
  option :subhash, type: Hash, collection: { type: SubConfig, key: :name }
end

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



35
36
37
38
# File 'lib/configsl/collection.rb', line 35

def self.included(base)
  base.include(Format) unless base.include?(Format)
  base.extend ClassMethods
end