class Codestrap::Object::Factory

Attributes

cli[RW]

CLI object @!attribute [rw] cli @return [Codestrap::CLI]

clients[RW]

Array of client objects @!attribute [rw] clients @return [Array<Codestrap::Client>]

config[RW]

Configuration object @!attribute [rw] config @return [Codestrap::Config]

dirs[RW]

Directories where to find static object files @!attribute [rw] files @return [Codestrap::Config]

Public Class Methods

new(*args) click to toggle source
# File lib/codestrap/object/factory.rb, line 12
def initialize(*args)
  @namespace = args.shift.capitalize if args.length > 0
  @namespace ||= 'Standard'
end

Public Instance Methods

objects() click to toggle source

Generate a hash of key, value pair If value is of type Hash it is converted into an [OpenStruct] object

@return [Hash]

# File lib/codestrap/object/factory.rb, line 41
def objects
  objects = {}
  scan.each_pair do |key, value|
    case value
      when Hash
        objects[key] = OpenStruct.new(value)
      else
        objects[key] = value
    end
  end
  objects
end
scan() click to toggle source

Scan for objects

@return [Hash]

# File lib/codestrap/object/factory.rb, line 57
def scan
  objects = {}
  scan_class = "Codestrap::Object::#{@namespace.to_s}".split('::').inject(Object) { |o, c| o.const_get c }
  klasses = scan_class.constants.map do |constant|
    "Codestrap::Object::Standard::#{constant.to_s}".split('::').inject(Object) { |o, c| o.const_get c }
  end
  Array(klasses).sort { |a, b| a.weight <=> b.weight }.each do |klass|
    klass.dirs    = @dirs
    klass.cli     = @cli
    klass.config  = @config
    klass.clients = @clients
    klass.objects.each_pair do |key, value|
      objects[key.downcase] = value
    end
  end
  objects
end
to_hash() click to toggle source
# File lib/codestrap/object/factory.rb, line 75
def to_hash
  objects = {}
  scan.each_pair do |key, value|
    if value.is_a?(Hash)
      objects[key] = value
    end
  end
  objects
end