Class: KathyLee
- Inherits:
-
Object
show all
- Includes:
- Singleton
- Defined in:
- lib/kathy_lee/kathy_lee.rb,
lib/kathy_lee/fakes.rb,
lib/generators/kathy_lee.rb,
lib/generators/kathy_lee/model/model_generator.rb
Overview
Defined Under Namespace
Modules: Generators
Classes: Attributes, Definition, Fakes
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#attributes(factory_name, attributes = {}, &block) ⇒ Object
-
#build(factory_name, attributes = {}) ⇒ Object
-
#create(factory_name, attributes = {}) ⇒ Object
-
#define(factory_name, attributes = {}, &block) ⇒ Object
-
#initialize ⇒ KathyLee
constructor
A new instance of KathyLee.
-
#sweatshop(factory_name, *options, count) ⇒ Object
-
#sweatshop!(factory_name, *options, count) ⇒ Object
Constructor Details
Returns a new instance of KathyLee.
9
10
11
12
|
# File 'lib/kathy_lee/kathy_lee.rb', line 9
def initialize
self.factories = {}
self.factory_attributes = {}
end
|
Instance Attribute Details
#factories ⇒ Object
Returns the value of attribute factories.
6
7
8
|
# File 'lib/kathy_lee/kathy_lee.rb', line 6
def factories
@factories
end
|
#factory_attributes ⇒ Object
Returns the value of attribute factory_attributes.
7
8
9
|
# File 'lib/kathy_lee/kathy_lee.rb', line 7
def factory_attributes
@factory_attributes
end
|
Class Method Details
.method_missing(sym, *args, &block) ⇒ Object
62
63
64
|
# File 'lib/kathy_lee/kathy_lee.rb', line 62
def method_missing(sym, *args, &block)
KathyLee.instance.send(sym, *args, &block)
end
|
Instance Method Details
#attributes(factory_name, attributes = {}, &block) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/kathy_lee/kathy_lee.rb', line 32
def attributes(factory_name, attributes = {}, &block)
if block_given?
self.factory_attributes[factory_name] = KathyLee::Attributes.new(attributes, &block)
end
if self.factory_attributes.has_key?(factory_name)
return self.factory_attributes[factory_name].process(attributes)
end
return nil
end
|
#build(factory_name, attributes = {}) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/kathy_lee/kathy_lee.rb', line 14
def build(factory_name, attributes = {})
if self.factories[factory_name.to_sym]
return self.factories[factory_name.to_sym].build(attributes)
else
self.define(factory_name, attributes) do
object = factory_name.to_s.classify.constantize.new(options)
object
end
self.build(factory_name, attributes)
end
end
|
#create(factory_name, attributes = {}) ⇒ Object
26
27
28
29
30
|
# File 'lib/kathy_lee/kathy_lee.rb', line 26
def create(factory_name, attributes = {})
object = self.build(factory_name, attributes)
object.save!
return object
end
|
#define(factory_name, attributes = {}, &block) ⇒ Object
42
43
44
|
# File 'lib/kathy_lee/kathy_lee.rb', line 42
def define(factory_name, attributes = {}, &block)
self.factories[factory_name.to_sym] = KathyLee::Definition.new(factory_name, attributes, &block)
end
|
#sweatshop(factory_name, *options, count) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/kathy_lee/kathy_lee.rb', line 46
def sweatshop(factory_name, *options, count)
results = []
count.times do
results << self.build(factory_name, (options.first || {}))
end
return results
end
|
#sweatshop!(factory_name, *options, count) ⇒ Object
54
55
56
57
58
|
# File 'lib/kathy_lee/kathy_lee.rb', line 54
def sweatshop!(factory_name, *options, count)
results = self.sweatshop(factory_name, *options, count)
results.each {|x| x.save!}
return results
end
|