Class: Machinist::Lathe

Inherits:
Object
  • Object
show all
Defined in:
lib/machinist/lathe.rb

Overview

When you make an object, the blueprint for that object is instance-evaled against a Lathe.

The Lathe implements all the methods that are available to the blueprint, including method_missing to let the blueprint define attributes.

Direct Known Subclasses

ActiveRecord::Lathe

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, serial_number, attributes = {}) ⇒ Lathe

Returns a new instance of Lathe.



10
11
12
13
14
15
16
17
# File 'lib/machinist/lathe.rb', line 10

def initialize(klass, serial_number, attributes = {})
  @klass               = klass
  @serial_number       = serial_number
  @assigned_attributes = {}

  @object              = @klass.new
  attributes.each {|key, value| assign_attribute(key, value) }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(attribute, *args, &block) ⇒ Object

:nodoc:



27
28
29
30
31
# File 'lib/machinist/lathe.rb', line 27

def method_missing(attribute, *args, &block) #:nodoc:
  unless attribute_assigned?(attribute)
    assign_attribute(attribute, make_attribute(attribute, args, &block))
  end
end

Instance Attribute Details

#objectObject (readonly)

Returns the object under construction.



25
26
27
# File 'lib/machinist/lathe.rb', line 25

def object
  @object
end

Instance Method Details

#snObject

Returns a unique serial number for the object under construction.



20
21
22
# File 'lib/machinist/lathe.rb', line 20

def sn
  @serial_number
end