hey_listen 0.0.4 → 0.0.5

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: e40af5bb9ca2983b1080f50efa3a5481609fecd9
4
- data.tar.gz: f556c903a5b7c53d2c8300d035ffd2d81fecb27d
3
+ metadata.gz: 59f431f5b684c1862fab29b3bb4320876712b5c6
4
+ data.tar.gz: 81d38c266e6e2b274a71e9f16b458ce673181f2d
5
5
  SHA512:
6
- metadata.gz: ea303fef535cb7f7fc809894e5d6208097dbe19797f123c59a4f97e901c7d1293e09c7fadaa1b62e9526c4cc07d1537671a515a1ed8a32946b4d62fced8efd18
7
- data.tar.gz: bc9282bb7dd6a3c0b2d2c2411df8fcacf296a31d68b8268197e1a378f23eaa617a2bc53edf05e03ec5ac03f23e518fc7cd6388cb46f206733dc7b820482b617d
6
+ metadata.gz: c56c52cbec5caad02aaf130c1d2ec75dc9aaa1095e4c1ce3c3265b6653a46146ccbb2ddafd96e7cb97fbbf1eb7cb25651f0c4b52daebe657d5b57081ceb807db
7
+ data.tar.gz: 80f99daea7134a05f9ff0d1b768a231863deb036438e011059ded57202451e6bdfbf678773c12083d35587f75d83ab4e7e6c2c60e80bc72eeab13c446d42dcd1
@@ -1,5 +1,7 @@
1
1
  module HeyListen
2
2
  class Notification < ActiveRecord::Base
3
+ self.table_name = 'notifications'
4
+
3
5
  belongs_to :user
4
6
  belongs_to :notifiable, polymorphic: true
5
7
 
@@ -8,7 +10,7 @@ module HeyListen
8
10
  def notification
9
11
  "Notifications::#{label}".constantize.new(notifiable, user)
10
12
  end
11
- delegate :accepted?, :requires_action?, :image, :text, :content, to: :notification
13
+ delegate :accepted?, :requires_action?, :image, :text, :content, :accepted, :requires_action?, :actions, to: :notification
12
14
 
13
15
  def date
14
16
  -> (d) {
@@ -5,10 +5,19 @@ module HeyListen
5
5
 
6
6
  desc 'Creates a Hey! Listen! migration for the Notifications table.'
7
7
 
8
+ def copy_initializer
9
+ template 'initializer.rb', 'config/initializers/hey_listen.rb'
10
+ end
11
+
8
12
  def copy_migration
9
13
  migration_template 'create_notifications.rb', 'db/migrate/create_notifications.rb'
10
14
  end
11
15
 
16
+ def copy_notifications_module
17
+ template 'notifications.rb', 'lib/notifications.rb'
18
+ template 'example_notification.rb', 'lib/notifications/example.rb'
19
+ end
20
+
12
21
  def self.next_migration_number(path)
13
22
  Time.now.utc.strftime("%Y%m%d%H%M%S")
14
23
  end
@@ -0,0 +1,24 @@
1
+ module Notifications
2
+ class Example < HeyListen::Notifications::Base
3
+ include Rails.application.routes.url_helpers
4
+
5
+ def path
6
+ polymorphic_path(@notifiable)
7
+ end
8
+
9
+ def image_src
10
+ asset_path('hey_listen/alert.png')
11
+ end
12
+
13
+ def content
14
+ [{
15
+ type: 'text',
16
+ text: 'Someone just went and did'
17
+ }, {
18
+ type: 'link',
19
+ text: 'something',
20
+ path: path
21
+ }]
22
+ end
23
+ end
24
+ end
@@ -0,0 +1 @@
1
+ require 'notifications'
@@ -0,0 +1,4 @@
1
+ Dir[Rails.root.join('lib/notifications/*.rb')].each { |f| require f }
2
+
3
+ module Notifications
4
+ end
@@ -0,0 +1,21 @@
1
+ module HeyListen
2
+ module ActsAsNotificationReceiver
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ def acts_as_notification_receiver
7
+ has_many :notifications, class_name: 'HeyListen::Notification', dependent: :destroy
8
+
9
+ include HeyListen::ActsAsNotificationReceiver::InstanceMethods
10
+ end
11
+ end
12
+
13
+ module InstanceMethods
14
+ def notify(label, notifiable)
15
+ notifications.create(label: label, notifiable: notifiable)
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ ActiveRecord::Base.send :include, HeyListen::ActsAsNotificationReceiver
@@ -0,0 +1,48 @@
1
+ module HeyListen
2
+ module Notifications
3
+ class Base
4
+ include ActionView::Helpers::AssetUrlHelper
5
+ include ActionDispatch::Routing::PolymorphicRoutes
6
+
7
+ def initialize(user, notifiable)
8
+ @user = user
9
+ @notifiable = notifiable
10
+ end
11
+
12
+ def path
13
+ polymorphic_path(@notifiable)
14
+ end
15
+
16
+ def image_src
17
+ asset_path('hey_listen/alert.png')
18
+ end
19
+
20
+ def image
21
+ {
22
+ src: image_src,
23
+ path: path
24
+ }
25
+ end
26
+
27
+ def content
28
+ []
29
+ end
30
+
31
+ def text
32
+ content.map { |e| e[:text] }.join(' ') + '.'
33
+ end
34
+
35
+ def requires_action?
36
+ false
37
+ end
38
+
39
+ def accepted?
40
+ false
41
+ end
42
+
43
+ def actions
44
+ {}
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module HeyListen
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/hey_listen.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "hey_listen/engine"
2
+ require 'hey_listen/acts_as_notification_receiver'
3
+ require 'hey_listen/notifications/base'
2
4
 
3
5
  module HeyListen
4
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hey_listen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Escobedo
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 4.1.4
19
+ version: 4.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 4.1.4
26
+ version: 4.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sqlite3
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -48,6 +48,7 @@ files:
48
48
  - MIT-LICENSE
49
49
  - README.rdoc
50
50
  - Rakefile
51
+ - app/assets/images/hey_listen/alert.png
51
52
  - app/assets/javascripts/hey_listen/application.js
52
53
  - app/assets/stylesheets/hey_listen/application.css
53
54
  - app/controllers/hey_listen/application_controller.rb
@@ -57,8 +58,13 @@ files:
57
58
  - config/routes.rb
58
59
  - lib/generators/hey_listen/install_generator.rb
59
60
  - lib/generators/templates/create_notifications.rb
61
+ - lib/generators/templates/example_notification.rb
62
+ - lib/generators/templates/initializer.rb
63
+ - lib/generators/templates/notifications.rb
60
64
  - lib/hey_listen.rb
65
+ - lib/hey_listen/acts_as_notification_receiver.rb
61
66
  - lib/hey_listen/engine.rb
67
+ - lib/hey_listen/notifications/base.rb
62
68
  - lib/hey_listen/version.rb
63
69
  - lib/tasks/hey_listen_tasks.rake
64
70
  homepage: http://github.com/codigojade/hey_listen