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.



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

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:



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

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.



23
24
25
# File 'lib/machinist/lathe.rb', line 23

def object
  @object
end

Instance Method Details

#snObject

Returns a unique serial number for the object under construction.



18
19
20
# File 'lib/machinist/lathe.rb', line 18

def sn
  @serial_number
end