jeffperrin-paperclip 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/object_mother.rb +37 -0
  2. metadata +53 -0
@@ -0,0 +1,37 @@
1
+ module ObjectMother
2
+ class Factory
3
+ @@index = 0
4
+ def self.spawn
5
+ raise 'No create method specified'
6
+ end
7
+ def self.populate(model)
8
+ raise 'No populate method specified for ' + model.to_s
9
+ end
10
+ def self.to_hash(model)
11
+ raise 'No to_hash method specified'
12
+ end
13
+ def self.unique(val)
14
+ @@index += 1
15
+ val.to_s + @@index.to_s
16
+ end
17
+ def self.unique_email(val)
18
+ user, domain = val.split('@')
19
+ unique(user) + '@' + domain
20
+ end
21
+ def self.create
22
+ obj = spawn
23
+ populate(obj)
24
+ yield obj if block_given?
25
+ obj
26
+ end
27
+ def self.create!(&block)
28
+ obj = create(&block)
29
+ obj.save!
30
+ obj
31
+ end
32
+ def self.create_as_hash(&block)
33
+ obj = create(&block)
34
+ to_hash obj
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jeffperrin-paperclip
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Perrin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-18 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: jeffperrin@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/object_mother.rb
26
+ has_rdoc: true
27
+ homepage: http://github.com/jeffperrin/object_mother
28
+ post_install_message:
29
+ rdoc_options: []
30
+
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: "0"
38
+ version:
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ requirements: []
46
+
47
+ rubyforge_project:
48
+ rubygems_version: 1.2.0
49
+ signing_key:
50
+ specification_version: 2
51
+ summary: Simple model creation for rails
52
+ test_files: []
53
+