dm-actionstamps-jwr 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -3
- data/dm-actionstamps.gemspec +1 -1
- data/lib/dm-actionstamps/actionstamps.rb +17 -10
- data/lib/dm-actionstamps/version.rb +1 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
= dm-actionstamps
|
2
2
|
|
3
3
|
A DataMapper plugin that works similar to the dm-timestamps in that it 'automagically' adds/updates the
|
4
|
-
created_
|
4
|
+
created_?_id, updated_?_id fields of your models.
|
5
|
+
|
6
|
+
This version creates both the created_?_id, updated_?_id fields and also adds "created_?" and "updated_?" methods to your model to retrieve the datamapper instance, e.g. the User object.
|
5
7
|
|
6
8
|
This is a completely rewritten version of the "rlivesey's"[http://github.com/rlivsey/] <tt>"dm-userstamp"[http://github.com/rlivsey/dm-userstamp]</tt> gem.
|
7
9
|
|
@@ -90,9 +92,11 @@ So given this usage scenario:
|
|
90
92
|
|
91
93
|
The Article instance should have the following:
|
92
94
|
|
93
|
-
@article.
|
94
|
-
@article.
|
95
|
+
@article.created_by_id => 99
|
96
|
+
@article.updated_by_id => 99
|
95
97
|
|
98
|
+
@article.created_by => User.get(99)
|
99
|
+
@article.updated_by => User.get(99)
|
96
100
|
|
97
101
|
== Customisations
|
98
102
|
|
data/dm-actionstamps.gemspec
CHANGED
@@ -77,25 +77,32 @@ module DataMapper
|
|
77
77
|
configs = { :suffix => args[0], :model => args[1] }
|
78
78
|
|
79
79
|
# do we have the fields :created_? / :updated_? declared, if not we declare them
|
80
|
-
if properties.any? { |p| p.name.to_s =~ /^(created|updated)_#{Regexp.escape(configs[:suffix].to_s)}$/ }
|
80
|
+
if properties.any? { |p| p.name.to_s =~ /^(created|updated)_#{Regexp.escape(configs[:suffix].to_s)}_id$/ }
|
81
81
|
# if they are declared then we use them
|
82
|
-
raise ArgumentError, "Full functionality NOT implemented yet. Please DO NOT declare your created_#{configs[:suffix]} / updated_#{configs[:suffix]} properties, they will be automatically declared by this plugin."
|
82
|
+
raise ArgumentError, "Full functionality NOT implemented yet. Please DO NOT declare your created_#{configs[:suffix]}_id / updated_#{configs[:suffix]}_id properties, they will be automatically declared by this plugin."
|
83
83
|
else
|
84
|
-
property "created_#{configs[:suffix]}".to_sym, Integer#, :default => 1
|
85
|
-
property "updated_#{configs[:suffix]}".to_sym, Integer#, :default => 1
|
84
|
+
property "created_#{configs[:suffix]}_id".to_sym, Integer#, :default => 1
|
85
|
+
property "updated_#{configs[:suffix]}_id".to_sym, Integer#, :default => 1
|
86
86
|
end
|
87
87
|
|
88
|
-
@actionstamps_receiver_properties = ["created_#{configs[:suffix]}".to_sym, "updated_#{configs[:suffix]}".to_sym ]
|
88
|
+
@actionstamps_receiver_properties = ["created_#{configs[:suffix]}_id".to_sym, "updated_#{configs[:suffix]}_id".to_sym ]
|
89
89
|
@actionstamps_model_class = configs[:model].to_s.capitalize
|
90
90
|
|
91
91
|
extend DataMapper::Actionstamps::ClassMethods
|
92
92
|
include DataMapper::Actionstamps::ReceiverMethods
|
93
|
-
|
94
|
-
|
93
|
+
|
95
94
|
class_eval(<<-END, __FILE__, __LINE__)
|
95
|
+
def created_#{configs[:suffix].to_s}
|
96
|
+
#{configs[:model]}.get(self.created_#{configs[:suffix].to_s}_id) unless self.created_#{configs[:suffix].to_s}_id.nil?
|
97
|
+
end
|
98
|
+
|
99
|
+
def updated_#{configs[:suffix].to_s}
|
100
|
+
#{configs[:model]}.get(self.updated_#{configs[:suffix].to_s}_id) unless self.updated_#{configs[:suffix].to_s}_id.nil?
|
101
|
+
end
|
102
|
+
|
96
103
|
def set_actionstamps
|
97
|
-
self.created_#{configs[:suffix].to_s} = #{configs[:model]}.current_#{configs[:model].to_s.downcase}.id if #{configs[:model]}.current_#{configs[:model].to_s.downcase} && self.new? && self.created_#{configs[:suffix].to_s}.nil?
|
98
|
-
self.updated_#{configs[:suffix].to_s} = #{configs[:model]}.current_#{configs[:model].to_s.downcase}.id if #{configs[:model]}.current_#{configs[:model].to_s.downcase}
|
104
|
+
self.created_#{configs[:suffix].to_s}_id = #{configs[:model]}.current_#{configs[:model].to_s.downcase}.id if #{configs[:model]}.current_#{configs[:model].to_s.downcase} && self.new? && self.created_#{configs[:suffix].to_s}_id.nil?
|
105
|
+
self.updated_#{configs[:suffix].to_s}_id = #{configs[:model]}.current_#{configs[:model].to_s.downcase}.id if #{configs[:model]}.current_#{configs[:model].to_s.downcase}
|
99
106
|
end
|
100
107
|
END
|
101
108
|
|
@@ -148,4 +155,4 @@ module DataMapper
|
|
148
155
|
|
149
156
|
end #/module Actionstamps
|
150
157
|
|
151
|
-
end #/module DataMapper
|
158
|
+
end #/module DataMapper
|