Class: FloorManager::Floor
- Inherits:
-
Object
- Object
- FloorManager::Floor
- Defined in:
- lib/floor_manager/floor.rb
Overview
A single floor under the supervision of the manager. This is basically a context in which unique/singleton instances and templates can coexist.
Defined Under Namespace
Classes: DSL
Instance Attribute Summary collapse
-
#employees ⇒ Object
readonly
Returns the value of attribute employees.
Class Method Summary collapse
Instance Method Summary collapse
- #attrs(something, overrides = {}) ⇒ Object
- #build(something, overrides = {}) ⇒ Object
- #create(something, overrides = {}) ⇒ Object
-
#initialize ⇒ Floor
constructor
A new instance of Floor.
-
#method_missing(sym, *args, &block) ⇒ Object
Allows production of new employees by calling their names as methods on the floor.
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Floor
Returns a new instance of Floor.
35 36 37 |
# File 'lib/floor_manager/floor.rb', line 35 def initialize @employees = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
Allows production of new employees by calling their names as methods on the floor.
With a definition of
one :dog do
end
you could call
floor.dog
and get the same as if you had called floor.build :dog
53 54 55 56 57 58 59 60 61 |
# File 'lib/floor_manager/floor.rb', line 53 def method_missing(sym, *args, &block) if args.size <= 1 && employees.has_key?(sym) attribute_overrides = {} attribute_overrides = args.first unless args.empty? employees[sym].build(self, attribute_overrides) else super end end |
Instance Attribute Details
#employees ⇒ Object (readonly)
Returns the value of attribute employees.
34 35 36 |
# File 'lib/floor_manager/floor.rb', line 34 def employees @employees end |
Class Method Details
Instance Method Details
#attrs(something, overrides = {}) ⇒ Object
69 70 71 |
# File 'lib/floor_manager/floor.rb', line 69 def attrs(something, overrides={}) employees[something.to_sym].attrs(self, overrides) end |
#build(something, overrides = {}) ⇒ Object
66 67 68 |
# File 'lib/floor_manager/floor.rb', line 66 def build(something, overrides={}) employees[something.to_sym].build(self, overrides) end |
#create(something, overrides = {}) ⇒ Object
63 64 65 |
# File 'lib/floor_manager/floor.rb', line 63 def create(something, overrides={}) employees[something.to_sym].create(self, overrides) end |
#reset ⇒ Object
73 74 75 76 77 |
# File 'lib/floor_manager/floor.rb', line 73 def reset employees.values.each do |employee| employee.reset end end |