async-messaging 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c1f28af4408645fbb76bcbeaab5282db811a477a
4
+ data.tar.gz: 34a9487a88ce6df074e1acbec08199666dad58a2
5
+ SHA512:
6
+ metadata.gz: fbada06d88a34b92db309417c6c608efe0358e061d9514bfe29037ee421959ed7865245a36b56ca7e53c4d805d00fd9f93a995ca7561d9abee6aab25134249e2
7
+ data.tar.gz: ed5e711d3836630c8dbeda7bcee582aa940e5615840b1251bb151d41cd15000ab3e32cd02c2c90ef7a9bbf706abe46754337a53647a3e999d62b9fcc35e10628
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ *.sassc
4
+ .sass-cache
5
+ capybara-*.html
6
+ .rspec
7
+ .rvmrc
8
+ /vendor/bundle
9
+ /log/*
10
+ /tmp/*
11
+ /db/*.sqlite3
12
+ /public/system/*
13
+ /coverage/
14
+ /spec/tmp/*
15
+ **.orig
16
+ rerun.txt
17
+ pickle-email-*.html
18
+ .project
19
+ config/initializers/secret_token.rb
20
+ .bundle
21
+ .config
22
+ .yardoc
23
+ Gemfile.lock
24
+ InstalledFiles
25
+ _yardoc
26
+ coverage
27
+ doc/
28
+ lib/bundler/man
29
+ pkg
30
+ rdoc
31
+ spec/reports
32
+ test/tmp
33
+ test/version_tmp
34
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in async-messaging.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,122 @@
1
+ # Async::Messaging
2
+
3
+ The Async Messaging gem (Ruby on Rails) aims to simplify User notifications when handling asynchronous calls within your application, via messaging.
4
+
5
+ *For example: you're using Delayed::Job (https://github.com/collectiveidea/delayed_job) and have completed a 'delayed' action, but want to notify the user about the status after it's completed. A simple flash[:notice] isn't going to work because you're outside User context.*
6
+
7
+ **NOTE: Currently this gem is under heavy development, function calls will change in the future**
8
+
9
+ The capabilities of async-messaging are required for a private project, which is MongoDB/ Mongoid backed. Alternate messaging systems are not capable of handing these requirements (https://www.ruby-toolbox.com/categories/User_Messaging_Systems).
10
+
11
+ ## Roadmap
12
+
13
+ * Version (0.0.1)
14
+
15
+ * Functional gem to push User notifications via flash messages
16
+
17
+ * Future features (subject to change)
18
+
19
+ * Javascript flash message pull
20
+ * Activerecord support
21
+ * Email style user messaging
22
+
23
+
24
+ ## Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+
28
+ gem 'async-messaging', github: "dblommesteijn/async-messaging"
29
+
30
+ And then execute:
31
+
32
+ $ bundle
33
+
34
+ ## Configuration
35
+
36
+ Generate initialize script for async-messaging
37
+
38
+ ```bash
39
+ $ rails g asyncmessaging:install
40
+ ```
41
+
42
+ **Configure initializer script with your Models** `config/initializer/async-messaging.rb`
43
+
44
+ ```ruby
45
+ # Async::Messaging initializer
46
+ # Use this hook to define your messaging setup
47
+
48
+ Async::Messaging.setup do |config|
49
+ # mongoid configuration
50
+ require 'devise/orm/mongoid'
51
+ # provide the root user instance (system messaging source)
52
+ # NOTE: this can/ should be a dummy account!
53
+ config.model_root = User.find("5333f81244656eccdc020000")
54
+ end
55
+ ```
56
+
57
+ **Add flash handler to your Controller** `app/controllers/application_controller.rb`
58
+
59
+ ```ruby
60
+ # handle flash messaging from Async::Messaging helper
61
+ include Async::Messaging::Controller
62
+ ```
63
+ NOTE: Async::Messaging::Controller adds `before_filter :help_async_messaging` that collects all user flash messages from the database and creates flashes.
64
+
65
+
66
+ **Cancel flash message behaviour (skip before_filter)**
67
+
68
+ ```ruby
69
+ skip_before_filter :help_async_messaging
70
+ ```
71
+
72
+ **Prepare your flash notification view**
73
+
74
+ Below is an example of flash view (in slimlang) and Bootstrap. The example will not show any values other than Strings, now we need to expand on this by switching `if key == :async_messaging`
75
+
76
+ ```haml
77
+ div.row
78
+ div.col-xs-12
79
+ - flash.each do |key, value|
80
+ - if key == :async_messaging
81
+ / async_messaging flash
82
+ - value.each do |notification|
83
+ - next if notification.empty?
84
+ div{class="alert alert-info fade in"}
85
+ a.href{data-dismiss="alert" class="close"}
86
+ li.fa.fa-times
87
+ / prettify the message
88
+ p
89
+ strong
90
+ = notification[:subject]
91
+ = "&nbsp;".html_safe
92
+ = notification[:content]
93
+ - else
94
+ / default flash
95
+ div{class="alert alert-info fade in"}
96
+ a.href{data-dismiss="alert" class="close"}
97
+ li.fa.fa-times
98
+ = value if value.is_a? String
99
+ ```
100
+
101
+
102
+ ## Generating Messages
103
+
104
+ Notify a user, send a system message.
105
+ *NOTE: These messages are consumed upon retreival.*
106
+
107
+ ```ruby
108
+ # sends a system message to a user as flash message
109
+ Async::Messaging::Notify.notify_user(User.first, subject: "System Notice", content: "How are you?", category: :flash, flags: [:notice])
110
+ ```
111
+
112
+ NOTE: on page reload the flash message is collected in the `ApplicationController` via the `before_filter` in `Async::Messaging::Controller`.
113
+
114
+
115
+
116
+ ## Contributing?
117
+
118
+ 1. Fork it ( http://github.com/dblommesteijn/async-messaging/fork )
119
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
120
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
121
+ 4. Push to the branch (`git push origin my-new-feature`)
122
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'async-messaging/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "async-messaging"
8
+ spec.version = Async::Messaging::VERSION
9
+ spec.authors = ["Dennis Blommesteijn"]
10
+ spec.email = ["dennis@blommesteijn.com"]
11
+ spec.summary = %q{User Messaging Async calls, compatible with Mongoid (Ruby on Rails) gem}
12
+ spec.description = %q{User Messaging Async calls, compatible with Mongoid (Ruby on Rails) gem}
13
+ spec.homepage = "https://github.com/dblommesteijn/async-messaging"
14
+ spec.license = "LGPLv3"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'mongoid', ['>= 3.0', '< 5']
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/async-messaging/version")
2
+ require File.expand_path(File.dirname(__FILE__) + "/async-messaging/notify")
3
+ require File.expand_path(File.dirname(__FILE__) + "/async-messaging/message")
4
+ require File.expand_path(File.dirname(__FILE__) + "/async-messaging/setup_config")
5
+ require File.expand_path(File.dirname(__FILE__) + "/async-messaging/setup")
6
+ require File.expand_path(File.dirname(__FILE__) + "/async-messaging/controller")
7
+
8
+ module Async
9
+ module Messaging
10
+ # Your code goes here...
11
+ end
12
+ end
@@ -0,0 +1,31 @@
1
+ module Async
2
+ module Messaging
3
+ module Controller
4
+
5
+ # collect all flash notifications from a given user
6
+ def notify_flash(user)
7
+ return if user.nil?
8
+ rs = Mongoid::Message.where(to: user.id, category: :flash)
9
+ # collect results (copy)
10
+ ret = rs.to_a
11
+ # remove from the database
12
+ rs.delete_all
13
+ # return the collected results
14
+ ret
15
+ end
16
+
17
+ # controller helper
18
+ def self.included(base)
19
+ base.before_filter :help_async_messaging
20
+ end
21
+ # before filter that creates flash messages
22
+ def help_async_messaging
23
+ # push flash_notices to flash.now
24
+ flash_notices = notify_flash(User.current).flat_map(&:to_h)
25
+ flash.now[:async_messaging] ||= []
26
+ flash.now[:async_messaging].concat flash_notices
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ module Async
4
+ module Messaging
5
+ module Mongoid
6
+ class Message
7
+
8
+ include ::Mongoid::Document
9
+ include ::Mongoid::Timestamps
10
+
11
+ field :from, type: String
12
+ field :to, type: String
13
+ field :date_read, type: Array
14
+ field :priority, type: Integer, default: 0
15
+
16
+ field :subject, type: String
17
+ field :content, type: String
18
+
19
+ field :category, type: String
20
+ field :flags, type: Array
21
+
22
+ def to_h
23
+ Hash[self.attributes].symbolize_keys
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ module Async
2
+ module Messaging
3
+
4
+ class Notify
5
+ class << self
6
+ def notify_user(target_user_instance, options={})
7
+ options[:subject] ||= ""
8
+ options[:content] ||= ""
9
+ options[:category] ||= :flash
10
+ options[:flags] ||= [:notice]
11
+ # collect source user
12
+ s = Async::Messaging.setup
13
+ from_user_id = s.model_root.id
14
+ target_user_id = target_user_instance.id
15
+ # create document entry
16
+ Mongoid::Message.create! options.merge({from: from_user_id, to: target_user_id})
17
+ end
18
+
19
+ def clear_all
20
+ Mongoid::Message.delete_all
21
+ end
22
+
23
+
24
+
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ module Async
2
+ module Messaging
3
+ @@setup_config ||= SetupConfig.new
4
+ class << self
5
+ def setup(&block)
6
+ if block_given?
7
+ block.call @@setup_config
8
+ else
9
+ @@setup_config
10
+ end
11
+ #yield self if block_given?
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module Async
2
+ module Messaging
3
+
4
+ class SetupConfig
5
+ attr_accessor :model, :model_root
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Async
2
+ module Messaging
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ module Asyncmessaging
2
+ module Generators
3
+
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path("../../templates", __FILE__)
6
+ desc "Creates a Async-messaging initializer in your application."
7
+
8
+ def copy_initializer
9
+ template "async_messaging.rb", "config/initializers/async_messaging.rb"
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ # Async::Messaging initializer
2
+ # Use this hook to define your messaging setup
3
+
4
+ Async::Messaging.setup do |config|
5
+ # mongoid configuration
6
+ require 'devise/orm/mongoid'
7
+ config.model_root = User.find("5333f81244656eccdc020000")
8
+ # TODO: other configs here!!
9
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: async-messaging
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dennis Blommesteijn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mongoid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.5'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.5'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ description: User Messaging Async calls, compatible with Mongoid (Ruby on Rails) gem
62
+ email:
63
+ - dennis@blommesteijn.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - Gemfile
70
+ - LICENSE
71
+ - README.md
72
+ - Rakefile
73
+ - async-messaging.gemspec
74
+ - lib/async-messaging.rb
75
+ - lib/async-messaging/controller.rb
76
+ - lib/async-messaging/message.rb
77
+ - lib/async-messaging/notify.rb
78
+ - lib/async-messaging/setup.rb
79
+ - lib/async-messaging/setup_config.rb
80
+ - lib/async-messaging/version.rb
81
+ - lib/generators/asyncmessaging/install_generator.rb
82
+ - lib/generators/templates/async_messaging.rb
83
+ homepage: https://github.com/dblommesteijn/async-messaging
84
+ licenses:
85
+ - LGPLv3
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.2.2
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: User Messaging Async calls, compatible with Mongoid (Ruby on Rails) gem
107
+ test_files: []