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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea33b8dd929767abff42ac3259cd5d670ce9ae51
4
- data.tar.gz: f74ad1bb74d830af2649384dc0544894350d75f4
3
+ metadata.gz: 4465e6e0b98be64bfc3e21fc054712fc665d731a
4
+ data.tar.gz: 25931fe558065536e96e8f9d2d6a8efa5a50fbe4
5
5
  SHA512:
6
- metadata.gz: 301742a7670577c170fe9548356b0868eb5d6408ad56ca818105d5ed8d789586175e6a7493940876d8718c3b023e3a86aab0e7c1c364f151a4b391157489fd50
7
- data.tar.gz: 7170ca096e87605b70bf33f708e4d18fb070c4abb4cbf2e37877a87d5f0f804b51afe691994591b2827a6ddc06a9485404978b1b8dfe93982a427fbb4f1d8a16
6
+ metadata.gz: 3d112d0258f6722441d34f1b441bf7b9457ccbf54fc6aeed6a19fafb2c9d10b676f6e182a6f9d706b1748bdf6b8b69b80014a406106cf2c39583996266d77498
7
+ data.tar.gz: 85c10b8cd6d2e5712a50729c247de1149e8abafd43c621c478995744e347cc9666bf0ee7eb676a967b94c62b6f1213462aa5b78f016ae5f5309fed406a447420
@@ -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
- def active
12
- find_by(active: true)
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 deactivate
17
- self.update_attributes(active: false)
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.try(:active?)
22
- self.class.where('id <> :id', id: self.id).where(active: true).
23
- map(&:deactivate)
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
@@ -1,3 +1,3 @@
1
1
  module Activator
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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.3
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
@@ -1,9 +0,0 @@
1
- module Activator
2
- class Railtie < Rails::Railtie
3
- initializer 'attached.initialize' do
4
- ActiveSupport.on_load(:active_record) do
5
- ActiveRecord::Base.send :include, Activator
6
- end
7
- end
8
- end
9
- end