Class: Codestrap::Object::Factory
- Inherits:
-
Object
- Object
- Codestrap::Object::Factory
- Defined in:
- lib/codestrap/object/factory.rb
Instance Attribute Summary collapse
-
#cli ⇒ Codestrap::CLI
CLI object.
-
#clients ⇒ Array<Codestrap::Client>
Array of client objects.
-
#config ⇒ Codestrap::Config
Configuration object.
-
#dirs ⇒ Codestrap::Config
Directories where to find static object files.
-
#files ⇒ Codestrap::Config
Directories where to find static object files.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Factory
constructor
A new instance of Factory.
-
#objects ⇒ Hash
Generate a hash of key, value pair If value is of type Hash it is converted into an [OpenStruct] object.
-
#scan ⇒ Hash
Scan for objects.
- #to_hash ⇒ Object
Constructor Details
#initialize(*args) ⇒ Factory
Returns a new instance of Factory.
12 13 14 15 |
# File 'lib/codestrap/object/factory.rb', line 12 def initialize(*args) @namespace = args.shift.capitalize if args.length > 0 @namespace ||= 'Standard' end |
Instance Attribute Details
#cli ⇒ Codestrap::CLI
CLI object
25 26 27 |
# File 'lib/codestrap/object/factory.rb', line 25 def cli @cli end |
#clients ⇒ Array<Codestrap::Client>
Array of client objects
35 36 37 |
# File 'lib/codestrap/object/factory.rb', line 35 def clients @clients end |
#config ⇒ Codestrap::Config
Configuration object
30 31 32 |
# File 'lib/codestrap/object/factory.rb', line 30 def config @config end |
#dirs ⇒ Codestrap::Config
Directories where to find static object files
20 21 22 |
# File 'lib/codestrap/object/factory.rb', line 20 def dirs @dirs end |
#files ⇒ Codestrap::Config
Directories where to find static object files
20 |
# File 'lib/codestrap/object/factory.rb', line 20 attr_accessor :dirs |
Instance Method Details
#objects ⇒ Hash
Generate a hash of key, value pair If value is of type Hash it is converted into an [OpenStruct] object
41 42 43 44 45 46 47 48 49 50 51 52 |
# 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 ⇒ Hash
Scan for objects
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# 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 ⇒ Object
75 76 77 78 79 80 81 82 83 |
# 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 |