Module: Such::Parts

Defined in:
lib/such/parts.rb

Class Method Summary collapse

Class Method Details

.make(part, thing, *plugs) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/such/parts.rb', line 3

def self.make(part, thing, *plugs)
  raise "Such::#{thing} not defined." unless Object.const_defined?("Such::#{thing}")
  plugs.each do |plug|
    if /^[^\W_]+_(?<klass>[^\W_]+)$/=~plug
      next unless $VERBOSE
      unless Object.const_defined?("Such::#{klass}")
        $stderr.puts "Warning: Such::#{klass} not defined yet."
      end
    else
      raise "Plugs must have the form key_class: #{plug}"
    end
  end
  Such.subclass part, thing,  <<-EOT
    attr_accessor :#{plugs.join(', :')}
    def self.plugs
      [:#{plugs.join(', :')}]
    end
    include Such::Part
  EOT
end