pg_advisory_lock 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ddeeb1356cb650c405bbd16569ac2e2c8d7cfb3e3c4315af9f55aee4a5594bd
4
- data.tar.gz: becf789c25d232dccb5ce1504f5bd6aeef9d1b491e9f6ab85a4d9b42ae5e5c77
3
+ metadata.gz: 2fe66a6a9bafd02afd8fd643bf1792ab0b9cadfc74f076a30e25873a885d5ca7
4
+ data.tar.gz: 6d65a6c45a2f948dc4ad6b46ebfa139787534dd992f0268c7ed1414c008ae31a
5
5
  SHA512:
6
- metadata.gz: 4e7ee3ae26d4c4413e13fad975c5dcd2adbdefc0a2b3c6b70a9b94fcffe44c4ec466b7655752dc0f98dab3951a1f2841314763d6e42ca0672a85c1b720837530
7
- data.tar.gz: 9c865edbfdafd873c29e83cd731e438a3d7b504872a3853e6c724549cfeee8f79804d157271b5bc4b06cc568c45f3f5e3f94df5c79df5e036fbd04303cf9a0d0
6
+ metadata.gz: 967d5773b005b24e609cf8b415ae6d51d91a12be020e20eb74c63036da765e0182911f83d2fb86511bc009152c0fb4457ee83a2fbad95f517914ed17ab659dee
7
+ data.tar.gz: d8dc937754f2316cfd65002147f562a1778eba09cbf7e4e9659c1159bef12c758d0bdfc2a54a429aba7146d69b0efc7ec27a4b16c886c62423283e8e01fcfe89
data/README.md CHANGED
@@ -54,7 +54,7 @@ To release a new version, update the version number in `version.rb`, and then ru
54
54
 
55
55
  ## Contributing
56
56
 
57
- Bug reports and pull requests are welcome on GitHub at https://github.com/senid231/pg_advisory_lock. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/senid231/pg_advisory_lock/blob/master/CODE_OF_CONDUCT.md).
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/didww/pg_advisory_lock. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/didww/pg_advisory_lock/blob/master/CODE_OF_CONDUCT.md).
58
58
 
59
59
 
60
60
  ## License
@@ -63,4 +63,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
63
63
 
64
64
  ## Code of Conduct
65
65
 
66
- Everyone interacting in the PgAdvisoryLock project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/senid231/pg_advisory_lock/blob/master/CODE_OF_CONDUCT.md).
66
+ Everyone interacting in the PgAdvisoryLock project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/didww/pg_advisory_lock/blob/master/CODE_OF_CONDUCT.md).
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'active_support/logger'
4
4
  require 'pg_sql_caller'
5
+ require 'active_support/core_ext/string/inflections'
5
6
 
6
7
  module PgAdvisoryLock
7
8
  class Base
@@ -10,7 +11,7 @@ module PgAdvisoryLock
10
11
  # Allows to use mutex in applications that uses same database.
11
12
 
12
13
  class_attribute :logger, instance_writer: false, default: ActiveSupport::Logger.new(STDOUT)
13
- class_attribute :_sql_caller_class, instance_writer: false, default: PgSqlCaller::Base
14
+ class_attribute :_sql_caller_class, instance_writer: false, default: 'PgSqlCaller::Base'
14
15
  class_attribute :_lock_names, instance_writer: false, default: {}
15
16
 
16
17
  class << self
@@ -86,11 +87,11 @@ module PgAdvisoryLock
86
87
  end
87
88
 
88
89
  def transaction_lock(lock_number)
89
- raise ArgumentError, 'block required when not within transaction' if !block_given? && !_sql_caller_class.transaction_open?
90
+ raise ArgumentError, 'block required when not within transaction' if !block_given? && !sql_caller_class.transaction_open?
90
91
 
91
92
  return perform_lock(lock_number) unless block_given?
92
93
 
93
- _sql_caller_class.transaction do
94
+ sql_caller_class.transaction do
94
95
  perform_lock(lock_number)
95
96
  yield
96
97
  end
@@ -110,11 +111,11 @@ module PgAdvisoryLock
110
111
  def perform_lock(lock_number)
111
112
  function_name = "pg_advisory#{'_xact' if transaction}_lock#{'_shared' if shared}"
112
113
 
113
- _sql_caller_class.execute("SELECT #{function_name}(#{lock_number})")
114
+ sql_caller_class.execute("SELECT #{function_name}(#{lock_number})")
114
115
  end
115
116
 
116
117
  def perform_unlock(lock_number)
117
- _sql_caller_class.select_value("SELECT pg_advisory_unlock#{'_shared' if shared}(#{lock_number})")
118
+ sql_caller_class.select_value("SELECT pg_advisory_unlock#{'_shared' if shared}(#{lock_number})")
118
119
  end
119
120
 
120
121
  # Converts lock name to number, because pg advisory lock functions accept only bigint numbers.
@@ -129,5 +130,11 @@ module PgAdvisoryLock
129
130
 
130
131
  lock_number.join(', ')
131
132
  end
133
+
134
+ def sql_caller_class
135
+ return @sql_caller_class if defined?(@sql_caller_class)
136
+
137
+ @sql_caller_class = _sql_caller_class.is_a?(String) ? _sql_caller_class.constantize : _sql_caller_class
138
+ end
132
139
  end
133
140
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgAdvisoryLock
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = 'Postgresql Advisory Lock for ActiveRecord'
12
12
  spec.description = 'Postgresql Advisory Lock for ActiveRecord.'
13
- spec.homepage = 'https://github.com/senid231/pg_advisory_lock'
13
+ spec.homepage = 'https://github.com/didww/pg_advisory_lock'
14
14
  spec.license = 'MIT'
15
15
  spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
16
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_advisory_lock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Talakevich
@@ -74,13 +74,13 @@ files:
74
74
  - lib/pg_advisory_lock/base.rb
75
75
  - lib/pg_advisory_lock/version.rb
76
76
  - pg_advisory_lock.gemspec
77
- homepage: https://github.com/senid231/pg_advisory_lock
77
+ homepage: https://github.com/didww/pg_advisory_lock
78
78
  licenses:
79
79
  - MIT
80
80
  metadata:
81
- homepage_uri: https://github.com/senid231/pg_advisory_lock
82
- source_code_uri: https://github.com/senid231/pg_advisory_lock
83
- changelog_uri: https://github.com/senid231/pg_advisory_lock
81
+ homepage_uri: https://github.com/didww/pg_advisory_lock
82
+ source_code_uri: https://github.com/didww/pg_advisory_lock
83
+ changelog_uri: https://github.com/didww/pg_advisory_lock
84
84
  post_install_message:
85
85
  rdoc_options: []
86
86
  require_paths: