has_notifications 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 53a42da5488ffcea3d23b132c53990764b553e2a
4
+ data.tar.gz: 2607df858f571372633543023a521f1ade575213
5
+ SHA512:
6
+ metadata.gz: 4cb8b5b2b87c13ab992e561934c043bac57decc8deba0d2d67a174692b1bc6bbca5af47164010ce5ef6424c9295741cc56c27b61ef1d16b019440c9385d27e1c
7
+ data.tar.gz: 7f0a04d378ede51f0c25e96186c80c0860caae6add05a4d05c2ed5de5742200ac339ba98abd4b82a36301b6ddac32184578c9e6039e467bcb09c5e7991a56d0a
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+
5
+ install:
6
+ - bundle install
7
+
8
+ cache: bundler
9
+
10
+ script: 'bundle exec rspec spec'
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in has_notifications.gemspec
4
+ gemspec
5
+
6
+ gem "rails", "~>4.2.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Vlad Zagorodniy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # Has Notifications
2
+
3
+ [![Build Status](https://travis-ci.org/vladzzag/has_notifications.svg)](https://travis-ci.org/vladzzag/has_notifications)
4
+
5
+ Simple notification system for Ruby on Rails.
6
+
7
+ ## Installation
8
+
9
+ Generate tables that are required by ```has_notification```:
10
+ ```shell
11
+ $ gem install has_notifications
12
+ $ rails generate has_notifications:migration
13
+ $ rake db:migrate
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ Model which will be notificated:
19
+ ```ruby
20
+ class User < ActiveRecord::Base
21
+ has_notifications
22
+ end
23
+ ```
24
+
25
+ Notification model:
26
+ ```ruby
27
+ class Notification < ActiveRecord::Base
28
+ acts_as_notification
29
+ end
30
+ ```
31
+
32
+ Notify:
33
+ ```ruby
34
+ vlad = User.create!(name: "Vlad")
35
+ notification = Notification.create!(message: "Hello, World!")
36
+
37
+ vlad.notify(notification)
38
+ ```
39
+
40
+ Get all notifications:
41
+ ```ruby
42
+ vlad = User.first
43
+ vlad.all_notifications
44
+ => [...]
45
+ ```
46
+
47
+ Get all unwatched notifications:
48
+ ```ruby
49
+ vlad = User.first
50
+ vlad.unwatched_notifications
51
+ => [...]
52
+ ```
53
+
54
+ Get all watched notifications:
55
+ ```ruby
56
+ vlad = User.first
57
+ vlad.watched_notifications
58
+ => [...]
59
+ ```
60
+
61
+ Mark notification as watched:
62
+ ```ruby
63
+ vlad = User.first
64
+ notification = vlad.unwatched_notifications[0]
65
+ => <...>
66
+ notification.mark_as_watched
67
+ ```
68
+
69
+ ## Contributing
70
+
71
+ 0. Take a look at TODO.txt
72
+ 1. Fork it ( https://github.com/vladzzag/has_notifications/fork )
73
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
74
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
75
+ 4. Push to the branch (`git push origin my-new-feature`)
76
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/TODO.txt ADDED
@@ -0,0 +1,3 @@
1
+ - cache
2
+ - dependencies
3
+ - callbacks
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "has_notifications"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'has_notifications/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "has_notifications"
8
+ spec.version = HasNotifications::VERSION
9
+ spec.authors = ["Vlad Zagorodniy"]
10
+ spec.email = ["vladzzag@gmail.com"]
11
+
12
+ spec.summary = %q{Notifications for Ruby on Rails}
13
+ spec.description = %q{Simple notifications for Ruby on Rails.}
14
+ spec.homepage = "https://github.com/vladzzag/has_notifications"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "sqlite3"
26
+ end
@@ -0,0 +1,20 @@
1
+ require 'rails/generators/migration'
2
+
3
+ module HasNotifications
4
+ class MigrationGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+ desc "fdsfsfs"
7
+
8
+ def self.source_root
9
+ File.join(File.dirname(__FILE__), "templates")
10
+ end
11
+
12
+ def self.next_migration_number(path)
13
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
14
+ end
15
+
16
+ def create_migration_file
17
+ migration_template "migration.rb", "db/migrate/has_notifications_migration.rb"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ class HasNotificationsMigration < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :hn_notifications do |t|
4
+ t.references :destination, polymorphic: true
5
+ t.references :notification, polymorphic: true
6
+
7
+ t.boolean :watched, default: false
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :hn_notifications, [:destination_id, :watched]
13
+ end
14
+
15
+ def self.down
16
+ drop_table :hn_notifications
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ require 'active_record'
2
+
3
+
4
+ module HasNotifications
5
+ module ActsAsNotification
6
+ def acts_as_notification
7
+ has_one :destination, class_name: "HasNotifications::HnNotification", as: :notification, dependent: :destroy
8
+ end
9
+ end
10
+ end
11
+
12
+ ActiveRecord::Base.extend(HasNotifications::ActsAsNotification)
@@ -0,0 +1,46 @@
1
+ require 'active_record'
2
+ require 'has_notifications/hn_notification'
3
+
4
+ module HasNotifications
5
+ module HasNotifications
6
+ def has_notifications
7
+ has_many :notifications, class_name: "::HasNotifications::HnNotification", as: :destination, dependent: :destroy
8
+
9
+ # create instance methods
10
+ class_eval do
11
+ def notify(notification)
12
+ #
13
+ # Notify destination
14
+ #
15
+ hn_notification = ::HasNotifications::HnNotification.new
16
+ hn_notification.destination = self
17
+ hn_notification.notification = notification
18
+ hn_notification.save
19
+ end
20
+
21
+ def all_notifications
22
+ #
23
+ # Get all notifications
24
+ #
25
+ self.notifications
26
+ end
27
+
28
+ def unwatched_notifications
29
+ #
30
+ # Get all unwatched notifications
31
+ #
32
+ self.notifications.where(watched: false)
33
+ end
34
+
35
+ def watched_notifications
36
+ #
37
+ # Get all watched notifications
38
+ #
39
+ self.notifications.where(watched: true)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ ActiveRecord::Base.extend(HasNotifications::HasNotifications)
@@ -0,0 +1,24 @@
1
+ require 'active_record'
2
+
3
+
4
+ module HasNotifications
5
+ class HnNotification < ::ActiveRecord::Base
6
+ # relations
7
+ belongs_to :destination, polymorphic: true, dependent: :destroy
8
+ belongs_to :notification, polymorphic: true, dependent: :destroy
9
+
10
+ def mark_as_watched
11
+ #
12
+ # Mark notification as watched
13
+ #
14
+ self.update_attribute(:watched, true)
15
+ end
16
+
17
+ def mark_as_unwatched
18
+ #
19
+ # Mark notification as unwatched
20
+ #
21
+ self.update_attribute(:watched, false)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module HasNotifications
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ require "has_notifications/version"
2
+ require "has_notifications/has_notifications"
3
+ require "has_notifications/acts_as_notification"
4
+
5
+
6
+ module HasNotifications
7
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_notifications
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vlad Zagorodniy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Simple notifications for Ruby on Rails.
70
+ email:
71
+ - vladzzag@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - TODO.txt
85
+ - bin/console
86
+ - bin/setup
87
+ - has_notifications.gemspec
88
+ - lib/generators/has_notifications/migration/migration_generator.rb
89
+ - lib/generators/has_notifications/migration/templates/migration.rb
90
+ - lib/has_notifications.rb
91
+ - lib/has_notifications/acts_as_notification.rb
92
+ - lib/has_notifications/has_notifications.rb
93
+ - lib/has_notifications/hn_notification.rb
94
+ - lib/has_notifications/version.rb
95
+ homepage: https://github.com/vladzzag/has_notifications
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.4.6
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Notifications for Ruby on Rails
119
+ test_files: []