Class: Cobble
- Inherits:
-
Object
show all
- Includes:
- Singleton
- Defined in:
- lib/cobble/fakes.rb,
lib/cobble/cobble.rb,
lib/cobble/errors.rb,
lib/cobble/binding.rb
Defined Under Namespace
Modules: Errors
Classes: Binding, Fakes
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#attribs(name) ⇒ Object
-
#attributes_for(factory, *args, &block) ⇒ Object
-
#build(factory, *args, &block) ⇒ Object
-
#create(factory, *args, &block) ⇒ Object
-
#define(factory_name, options = {}, &block) ⇒ Object
-
#define_attributes(name, options = {}) ⇒ Object
-
#initialize ⇒ Cobble
constructor
-
#method_missing(sym, *args, &block) ⇒ Object
-
#reset! ⇒ Object
Constructor Details
#initialize ⇒ Cobble
7
8
9
|
# File 'lib/cobble/cobble.rb', line 7
def initialize self.reset!
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/cobble/cobble.rb', line 44
def method_missing(sym, *args, &block)
meth = sym.to_s
case meth
when /^build_(.+)$/
return self.build($1, *args, &block)
when /^attributes_for_(.+)$/
return self.attributes_for($1, *args, &block)
when /^create_(.+)$/
return self.create($1, *args, &block)
else
return self.create(sym, *args, &block)
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
5
6
7
|
# File 'lib/cobble/cobble.rb', line 5
def attributes
@attributes
end
|
#factories ⇒ Object
Returns the value of attribute factories.
4
5
6
|
# File 'lib/cobble/cobble.rb', line 4
def factories
@factories
end
|
Class Method Details
.method_missing(sym, *args, &block) ⇒ Object
60
61
62
|
# File 'lib/cobble/cobble.rb', line 60
def method_missing(sym, *args, &block)
Cobble.instance.send(sym, *args, &block)
end
|
Instance Method Details
#attribs(name) ⇒ Object
24
25
26
|
# File 'lib/cobble/cobble.rb', line 24
def attribs(name)
self.attributes[name.to_sym] || {}
end
|
#attributes_for(factory, *args, &block) ⇒ Object
38
39
40
41
42
|
# File 'lib/cobble/cobble.rb', line 38
def attributes_for(factory, *args, &block)
fb = self.cobble_binding(factory.to_sym, :build, *args)
fb.execute {}
return fb.options
end
|
#build(factory, *args, &block) ⇒ Object
28
29
30
|
# File 'lib/cobble/cobble.rb', line 28
def build(factory, *args, &block)
return execute(factory.to_sym, :build, *args)
end
|
#create(factory, *args, &block) ⇒ Object
32
33
34
35
36
|
# File 'lib/cobble/cobble.rb', line 32
def create(factory, *args, &block)
res = self.execute(factory.to_sym, :create, *args)
res.save!
return res
end
|
#define(factory_name, options = {}, &block) ⇒ Object
16
17
18
|
# File 'lib/cobble/cobble.rb', line 16
def define(factory_name, options = {}, &block)
self.factories[factory_name.to_sym] = [options, block]
end
|
#define_attributes(name, options = {}) ⇒ Object
20
21
22
|
# File 'lib/cobble/cobble.rb', line 20
def define_attributes(name, options = {})
self.attributes[name.to_sym] = options
end
|
#reset! ⇒ Object
11
12
13
14
|
# File 'lib/cobble/cobble.rb', line 11
def reset!
self.factories = {}
self.attributes = {}
end
|