state-notifier 0.0.1 → 0.0.2

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: e931e03a15112ee3a7b45ce3375dfeff90a3c9eb
4
- data.tar.gz: 47cd597c6dc61ffe65ca1d0d20918e2dbd5f83f4
3
+ metadata.gz: 5a486acbfdf6f0523762786f7883f6dbe4daf2e8
4
+ data.tar.gz: 129146b1d147f4b21977629bf00d78eb83a5e56e
5
5
  SHA512:
6
- metadata.gz: 4cf56313b6d07339a654f413ab672c8b27c413a669f87b998e1534b1657980b973b5bad8642594bb22bc4b041e264b9972558a37d3f857963c7ea282b8ab6e95
7
- data.tar.gz: ca07eefdab07244721a0abff9b515e0abf6a18bd90ed4df59914a8a113305b30ee840a5fe37ac64a419ed3dd77acc3efb58850c9fcf5cabd2e7cda8567f1e319
6
+ metadata.gz: 600c88655af39a66129dc332e0eb27c44448bfba8af3811e660df0eb0ffad3584374a46c1d5c85fdd3f36514dc7b95b65b11f27ba280b74f11450b81ef660cf6
7
+ data.tar.gz: a5118a3efe600f89e52e464501df31c8856a21315d9cd773e5bb95c21cc98b01b28634426797b0a64bc0b3093457b4b758c3d8132963baf439cae8cbf4b8e7bf
@@ -0,0 +1,5 @@
1
+ module State
2
+ module Notifier
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,48 @@
1
+ require "state/notifier/version"
2
+
3
+ module State
4
+ module Notifier
5
+ extend ActiveSupport::Concern
6
+
7
+ def notify_targets(event)
8
+ name = self.class.name.underscore
9
+ method = [name, event] * '_'
10
+
11
+ targets = self.class.notification_targets.map {|m| send(m)}.flatten
12
+ Rails.logger.debug "StateNotifier: notifying #{method}, #{targets.size} targets"
13
+
14
+ targets.each do |t|
15
+ t.send(method, self) if t.respond_to?(method)
16
+ end
17
+ end
18
+
19
+ def notify_transition(transition)
20
+ notify_targets transition.event
21
+ notify_targets transition.to unless transition.to == transition.from
22
+ end
23
+
24
+ included do
25
+ after_create {notify_targets :created}
26
+ after_update {notify_targets :updated unless (changed - self.class.reserved_attributes).empty?}
27
+ if respond_to?(:state_machine)
28
+ state_machine do
29
+ after_transition { |record, transition| record.notify_transition transition }
30
+ end
31
+ end
32
+ end
33
+
34
+ module ClassMethods
35
+ def notification_targets(*values)
36
+ if values.present?
37
+ @notification_targets = values
38
+ else
39
+ @notification_targets
40
+ end
41
+ end
42
+
43
+ def reserved_attributes
44
+ %w[created_at updated_at state]
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,11 +1,11 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'state_notifier/version'
4
+ require 'state/notifier/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "state-notifier"
8
- spec.version = StateNotifier::VERSION
8
+ spec.version = State::Notifier::VERSION
9
9
  spec.authors = ["Vitaly Kushner"]
10
10
  spec.email = ["vitaly@astrails.com"]
11
11
  spec.description = %q{Simple gem to notify 'subscribers' about record state changes.}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state-notifier
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
  - Vitaly Kushner
@@ -64,8 +64,8 @@ files:
64
64
  - LICENSE.txt
65
65
  - README.md
66
66
  - Rakefile
67
- - lib/state_notifier.rb
68
- - lib/state_notifier/version.rb
67
+ - lib/state/notifier.rb
68
+ - lib/state/notifier/version.rb
69
69
  - state-notifier.gemspec
70
70
  homepage: https://github.com/vitaly/state-notifier
71
71
  licenses:
@@ -1,3 +0,0 @@
1
- module StateNotifier
2
- VERSION = "0.0.1"
3
- end
@@ -1,46 +0,0 @@
1
- require "state_notifier/version"
2
-
3
- module StateNotifier
4
- extend ActiveSupport::Concern
5
-
6
- def notify_targets(event)
7
- name = self.class.name.underscore
8
- method = [name, event] * '_'
9
-
10
- targets = self.class.notification_targets.map {|m| send(m)}.flatten
11
- Rails.logger.debug "StateNotifier: notifying #{method}, #{targets.size} targets"
12
-
13
- targets.each do |t|
14
- t.send(method, self) if t.respond_to?(method)
15
- end
16
- end
17
-
18
- def notify_transition(transition)
19
- notify_targets transition.event
20
- notify_targets transition.to unless transition.to == transition.from
21
- end
22
-
23
- included do
24
- after_create {notify_targets :created}
25
- after_update {notify_targets :updated unless (changed - self.class.reserved_attributes).empty?}
26
- if respond_to?(:state_machine)
27
- state_machine do
28
- after_transition { |record, transition| record.notify_transition transition }
29
- end
30
- end
31
- end
32
-
33
- module ClassMethods
34
- def notification_targets(*values)
35
- if values.present?
36
- @notification_targets = values
37
- else
38
- @notification_targets
39
- end
40
- end
41
-
42
- def reserved_attributes
43
- %w[created_at updated_at state]
44
- end
45
- end
46
- end