duplicate_it 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/duplicate_it.rb +18 -8
- metadata +3 -3
data/lib/duplicate_it.rb
CHANGED
@@ -1,14 +1,25 @@
|
|
1
1
|
module DuplicateIt
|
2
|
+
|
3
|
+
class RecordSaveError < StandardError
|
4
|
+
attr_reader :record
|
5
|
+
|
6
|
+
def initialize(record)
|
7
|
+
puts "Error saving #{record}"
|
8
|
+
puts "Error trace: #{record.errors.inspect}"
|
9
|
+
@record = record
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
2
13
|
def self.included(base)
|
3
14
|
base.extend(ClassMethods)
|
4
15
|
end
|
5
16
|
|
6
17
|
module ClassMethods
|
7
|
-
#Test method
|
8
|
-
def duplicate_it(*args)
|
9
|
-
puts "------- from duplicate_it --------"
|
10
|
-
puts args.inspect
|
11
|
-
end
|
18
|
+
# #Test method
|
19
|
+
# def duplicate_it(*args)
|
20
|
+
# puts "------- from duplicate_it --------"
|
21
|
+
# puts args.inspect
|
22
|
+
# end
|
12
23
|
end
|
13
24
|
|
14
25
|
def duplicate
|
@@ -27,8 +38,7 @@ module DuplicateIt
|
|
27
38
|
if duplicate_record.save
|
28
39
|
return duplicate_record
|
29
40
|
else
|
30
|
-
|
31
|
-
puts "Error trace: #{duplicate_record.errros.inspect}"
|
41
|
+
raise RecordSaveError.new(duplicate_record)
|
32
42
|
end
|
33
43
|
return nil
|
34
44
|
end
|
@@ -68,4 +78,4 @@ end
|
|
68
78
|
#Adding to ActiveRecord::Base
|
69
79
|
class ActiveRecord::Base
|
70
80
|
include DuplicateIt
|
71
|
-
end
|
81
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duplicate_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ cert_chain: []
|
|
12
12
|
date: 2012-04-04 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: A simple gem to dulicate a model instance, including its 'has_many' assocaited
|
15
|
-
objects
|
15
|
+
objects. Fixed typo and added standard error exception
|
16
16
|
email: praveen.kumar.sinha@gmail.com
|
17
17
|
executables: []
|
18
18
|
extensions: []
|
@@ -39,7 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
39
|
version: '0'
|
40
40
|
requirements: []
|
41
41
|
rubyforge_project:
|
42
|
-
rubygems_version: 1.8.
|
42
|
+
rubygems_version: 1.8.10
|
43
43
|
signing_key:
|
44
44
|
specification_version: 3
|
45
45
|
summary: DuplicateIt!
|