notifly 0.1.2 → 0.2.0

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: 079f1db58c119ea5ec0aa5b487c0aa45f6b24d61
4
- data.tar.gz: b1a215bc6e1d3caccafedd29e86c2ee5e90467df
3
+ metadata.gz: 939b12ea220c250f5b9e543f70c97f344fc0e973
4
+ data.tar.gz: 6c827c9a14c21d476ddb6bad7b17a22f29e21fd5
5
5
  SHA512:
6
- metadata.gz: 3aa005a8e84945e9228599e91a3b791a8ff8a9923af1cc5cff9e043e5bcd0e8a47ad9c17586ba5002183e2a28032be4b32d83f4ed93cc7ad48044f96ab3a2991
7
- data.tar.gz: a31efb84696178c8126b037f221a4e0cab4e5f4e3f4779eea11071fbcc5422c04be383b9b8820769726dc9ff8e71a83a3d695828e315ede74707f816d1fda7bb
6
+ metadata.gz: 275d3eb8008e16314a5bb02fea4094dea61c905b750d42a2200a1a3d16aa84319943abb33ad76bb266da07f85bd7eb069588cf11d26cae85f6f12b9c1554df5e
7
+ data.tar.gz: 262dd1bc12350d735cb64f35322fbcb44fb9aa96666ac5063d492caf16d9b3f69f7f95c5636b6227de190e64b29a2be34d2fbc95dcb48bf092d0a62356ddfe80
data/README.md CHANGED
@@ -16,6 +16,7 @@ In actual version, notifications are composed by:
16
16
  - Read: flag that records if the receiver read the notification
17
17
  - Seen: flag that records if the receiver seen the notification
18
18
  - If and Unless: used to create notifications conditionally
19
+ - type: helper
19
20
 
20
21
 
21
22
  # Install
@@ -41,7 +41,7 @@ module Notifly
41
41
 
42
42
  def current_user_notifications
43
43
  @user = current_user
44
- @user.notifly_notifications.not_only_mail
44
+ @user.notifly_notifications(:notification).not_only_mail
45
45
  end
46
46
 
47
47
  def count_unseen
@@ -4,7 +4,7 @@ module Notifly
4
4
  belongs_to :sender, polymorphic: true
5
5
  belongs_to :receiver, polymorphic: true
6
6
 
7
- before_validation :convert_data, :set_template, :set_mail
7
+ before_validation :convert_data, :set_defaults
8
8
 
9
9
  scope :all_from, -> (receiver) { where(receiver: receiver) }
10
10
  scope :unseen, -> { where(seen: false) }
@@ -30,7 +30,7 @@ module Notifly
30
30
  where(created_at: (notifications.first.created_at..notifications.last.created_at))
31
31
  end
32
32
 
33
- validates :receiver, :template, :mail, presence: true
33
+ validates :receiver, :template, :mail, :kind, presence: true
34
34
 
35
35
  def data
36
36
  YAML.load(read_attribute(:data))
@@ -41,12 +41,10 @@ module Notifly
41
41
  self.data = read_attribute(:data).to_json
42
42
  end
43
43
 
44
- def set_template
44
+ def set_defaults
45
+ self.mail ||= :never
46
+ self.kind ||= :notification
45
47
  self.template ||= :default
46
48
  end
47
-
48
- def set_mail
49
- self.mail ||= :never
50
- end
51
49
  end
52
50
  end
@@ -0,0 +1,5 @@
1
+ class AddKindToNotiflyNotification < ActiveRecord::Migration
2
+ def change
3
+ add_column :notifly_notifications, :kind, :string, default: :notification
4
+ end
5
+ end
@@ -101,10 +101,12 @@ module Notifly
101
101
  end
102
102
  rescue => e
103
103
  logger.error "Something goes wrong with Notifly, will ignore: #{e}"
104
+ raise e if not Rails.env.production?
104
105
  end
105
106
 
106
- def notifly_notifications
107
- Notifly::Notification.all_from(self)
107
+ def notifly_notifications(kind=nil)
108
+ notifications = Notifly::Notification.all_from(self)
109
+ kind.present? ? notifications.where(kind: kind) : notifications
108
110
  end
109
111
 
110
112
  private
@@ -123,12 +125,16 @@ module Notifly
123
125
  end
124
126
 
125
127
  def _eval_for(key, value)
126
- if [:template, :mail].include? key.to_sym
128
+ if [:template, :mail, :kind].include? key.to_sym
127
129
  value
128
130
  elsif value == :self
129
131
  self
130
132
  else
131
- send(value)
133
+ if value.is_a? Proc
134
+ instance_exec &value
135
+ else
136
+ send(value)
137
+ end
132
138
  end
133
139
  end
134
140
  end
@@ -3,7 +3,7 @@ module Notifly
3
3
  module Options
4
4
  class Fly
5
5
  attr_accessor :before, :after, :template, :sender, :receiver, :target,
6
- :if, :unless, :data, :mail
6
+ :if, :unless, :data, :mail, :kind
7
7
 
8
8
  def initialize(options={})
9
9
  options = options.fetch(:default_values, options)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Passalini
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-10 00:00:00.000000000 Z
12
+ date: 2014-12-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -203,6 +203,7 @@ files:
203
203
  - db/migrate/20141104150224_add_data_to_notification.rb
204
204
  - db/migrate/20141117193436_add_seen_to_notifly_notification.rb
205
205
  - db/migrate/20141125165636_add_mail_to_notifly_notifications.rb
206
+ - db/migrate/20141212122918_add_kind_to_notifly_notification.rb
206
207
  - lib/generators/notifly/install/install_generator.rb
207
208
  - lib/generators/notifly/install/templates/config/initializers/notifly.rb
208
209
  - lib/generators/notifly/install/utils.rb