programmable-ventouse 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -1,2 +1,7 @@
1
- TODO:
2
- create fake mysqlplus-adapter using mysql_compat
1
+ = ventouse
2
+
3
+ Why vantouse? Why not?
4
+
5
+ == to-do
6
+
7
+ create fake mysqlplus-adapter using mysql_compat
@@ -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
@@ -0,0 +1,5 @@
1
+ class ActiveRecord::Base
2
+ alias save save_without_transactions
3
+ alias save! save_without_transactions!
4
+ alias destroy destroy_without_transactions
5
+ end
@@ -1,5 +1,5 @@
1
1
  class String
2
2
  def filter_prefix prefix
3
- self.start_with?(prefix) ? self[prefix.to_s.length, self.length] : self
3
+ self.starts_with?(prefix) ? self[prefix.to_s.length, self.length] : self
4
4
  end
5
5
  end
data/lib/ventouse.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'ventouse/ar_touch'
1
2
  require 'ventouse/filter_prefix'
2
3
  require 'ventouse/module_declarations'
3
4
  require 'ventouse/rescue_ext'
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.1
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