activator 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/activator.rb +32 -9
- data/lib/activator/version.rb +1 -1
- metadata +1 -2
- data/lib/activator/railtie.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4465e6e0b98be64bfc3e21fc054712fc665d731a
|
4
|
+
data.tar.gz: 25931fe558065536e96e8f9d2d6a8efa5a50fbe4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d112d0258f6722441d34f1b441bf7b9457ccbf54fc6aeed6a19fafb2c9d10b676f6e182a6f9d706b1748bdf6b8b69b80014a406106cf2c39583996266d77498
|
7
|
+
data.tar.gz: 85c10b8cd6d2e5712a50729c247de1149e8abafd43c621c478995744e347cc9666bf0ee7eb676a967b94c62b6f1213462aa5b78f016ae5f5309fed406a447420
|
data/lib/activator.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'activator/railtie' if defined?(Rails)
|
2
|
-
|
3
1
|
module Activator
|
4
2
|
extend ActiveSupport::Concern
|
5
3
|
|
@@ -8,18 +6,43 @@ module Activator
|
|
8
6
|
end
|
9
7
|
|
10
8
|
module ClassMethods
|
11
|
-
|
12
|
-
|
9
|
+
@@used_activator_field = :active
|
10
|
+
|
11
|
+
def activator_field(name)
|
12
|
+
@@used_activator_field = name.to_sym
|
13
|
+
end
|
14
|
+
|
15
|
+
def used_activator_field
|
16
|
+
@@used_activator_field
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(name, *args)
|
20
|
+
if name == used_activator_field
|
21
|
+
activator_search_item
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def activator_search_item
|
29
|
+
find_by(:"#{used_activator_field}" => true)
|
13
30
|
end
|
14
31
|
end
|
15
32
|
|
16
|
-
def
|
17
|
-
self.update_attributes(
|
33
|
+
def activator_deactivate!
|
34
|
+
self.update_attributes(:"#{activator_field}" => false)
|
18
35
|
end
|
19
36
|
|
37
|
+
private
|
20
38
|
def deactivate_others
|
21
|
-
return unless self.
|
22
|
-
self.class.where('id <> :id', id: self.id).
|
23
|
-
|
39
|
+
return unless self.send("#{activator_field}?".to_sym)
|
40
|
+
self.class.where('id <> :id', id: self.id).
|
41
|
+
where(:"#{activator_field}" => true).
|
42
|
+
map(&:activator_deactivate!)
|
43
|
+
end
|
44
|
+
|
45
|
+
def activator_field
|
46
|
+
self.class.used_activator_field
|
24
47
|
end
|
25
48
|
end
|
data/lib/activator/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jelmer Snoeck
|
@@ -59,7 +59,6 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- lib/activator/railtie.rb
|
63
62
|
- lib/activator/version.rb
|
64
63
|
- lib/activator.rb
|
65
64
|
- MIT-LICENSE
|