programmable-ventouse 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +7 -2
- data/lib/ventouse/ar_touch.rb +32 -0
- data/lib/ventouse/disable_transactions.rb +5 -0
- data/lib/ventouse/filter_prefix.rb +1 -1
- data/lib/ventouse.rb +1 -0
- metadata +3 -1
data/README
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Timestamp
|
3
|
+
unless method_defined? :touch
|
4
|
+
# Saves the record with the updated_at/on attributes set to the current time.
|
5
|
+
# If the save fails because of validation errors, an ActiveRecord::RecordInvalid exception is raised.
|
6
|
+
# If an attribute name is passed, that attribute is used for the touch instead of the updated_at/on attributes.
|
7
|
+
#
|
8
|
+
# Examples:
|
9
|
+
#
|
10
|
+
# product.touch # updates updated_at
|
11
|
+
# product.touch(:designed_at) # updates the designed_at attribute
|
12
|
+
def touch(attribute = nil)
|
13
|
+
current_time = current_time_from_proper_timezone
|
14
|
+
|
15
|
+
if attribute
|
16
|
+
write_attribute(attribute, current_time)
|
17
|
+
else
|
18
|
+
write_attribute('updated_at', current_time) if respond_to?(:updated_at)
|
19
|
+
write_attribute('updated_on', current_time) if respond_to?(:updated_on)
|
20
|
+
end
|
21
|
+
|
22
|
+
save!
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
unless method_defined? :current_time_from_proper_timezone
|
27
|
+
def current_time_from_proper_timezone
|
28
|
+
self.class.default_timezone == :utc ? Time.now.utc : Time.now
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/ventouse.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: programmable-ventouse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilia Ablamonov
|
@@ -34,6 +34,8 @@ extra_rdoc_files: []
|
|
34
34
|
files:
|
35
35
|
- README
|
36
36
|
- lib/ventouse
|
37
|
+
- lib/ventouse/ar_touch.rb
|
38
|
+
- lib/ventouse/disable_transactions.rb
|
37
39
|
- lib/ventouse/filter_prefix.rb
|
38
40
|
- lib/ventouse/module_declarations.rb
|
39
41
|
- lib/ventouse/mysql_compat.rb
|