-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid globally polluting ::Object class
- Loading branch information
Showing
14 changed files
with
50 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
using Bullet::Ext::Object | ||
|
||
module Bullet | ||
module Detector | ||
class Association < Base | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
using Bullet::Ext::Object | ||
|
||
module Bullet | ||
module Detector | ||
class CounterCache < Base | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
using Bullet::Ext::Object | ||
using Bullet::Ext::String | ||
|
||
module Bullet | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
class Object | ||
def bullet_key | ||
"#{self.class}:#{bullet_primary_key_value}" | ||
end | ||
module Bullet | ||
module Ext | ||
module Object | ||
refine ::Object do | ||
def bullet_key | ||
"#{self.class}:#{bullet_primary_key_value}" | ||
end | ||
|
||
def bullet_primary_key_value | ||
return if respond_to?(:persisted?) && !persisted? | ||
def bullet_primary_key_value | ||
return if respond_to?(:persisted?) && !persisted? | ||
|
||
if self.class.respond_to?(:primary_keys) && self.class.primary_keys | ||
primary_key = self.class.primary_keys | ||
elsif self.class.respond_to?(:primary_key) && self.class.primary_key | ||
primary_key = self.class.primary_key | ||
else | ||
primary_key = :id | ||
end | ||
if self.class.respond_to?(:primary_keys) && self.class.primary_keys | ||
primary_key = self.class.primary_keys | ||
elsif self.class.respond_to?(:primary_key) && self.class.primary_key | ||
primary_key = self.class.primary_key | ||
else | ||
primary_key = :id | ||
end | ||
|
||
bullet_join_potential_composite_primary_key(primary_key) | ||
end | ||
bullet_join_potential_composite_primary_key(primary_key) | ||
end | ||
|
||
private | ||
private | ||
|
||
def bullet_join_potential_composite_primary_key(primary_keys) | ||
return send(primary_keys) unless primary_keys.is_a?(Enumerable) | ||
def bullet_join_potential_composite_primary_key(primary_keys) | ||
return send(primary_keys) unless primary_keys.is_a?(Enumerable) | ||
|
||
primary_keys.map { |primary_key| send primary_key } | ||
.join(',') | ||
primary_keys.map { |primary_key| send primary_key } | ||
.join(',') | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
using Bullet::Ext::Object | ||
using Bullet::Ext::String | ||
|
||
module Bullet | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
require 'spec_helper' | ||
|
||
using Bullet::Ext::Object | ||
|
||
module Bullet | ||
module Detector | ||
describe Association do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
require 'spec_helper' | ||
|
||
using Bullet::Ext::Object | ||
|
||
module Bullet | ||
module Registry | ||
describe Object do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters