inboxes 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -33,19 +33,15 @@ By default, the gem provides localized phrases for Russian and English languages
33
33
  #Integration with Faye
34
34
 
35
35
  1. Add `gem "faye"` to your Gemfile and run `bundle install`. Install Faye by [the screencast](http://railscasts.com/episodes/260-messaging-with-faye)
36
- 2. Create `messaging.js` in `app/assets/javascripts/` with these lines:
37
-
38
- /*
39
- = require inboxes/faye
40
- */
36
+ 2. Create `messaging.js` in `app/assets/javascripts/` with these line: `= require inboxes/faye`
41
37
 
42
38
  3. Copy or replace 2 views from Inboxes example app to your application: [app/views/inboxes/messages/_form](https://github.com/kirs/inboxes-app/blob/master/app/views/inboxes/messages/_form.html.haml) and [app/views/inboxes/messages/create](https://github.com/kirs/inboxes-app/blob/master/app/views/inboxes/messages/create.js.erb)
43
39
 
44
40
  4. Add config parameters to your application config (last 2 are not necessary):
45
-
46
- config.inboxes.faye_enabled = true
47
- config.inboxes.faye_host = "inboxes-app.dev" # localhost by default
48
- config.inboxes.faye_port = 9292 # 9292 by default
41
+
42
+ `config.inboxes.faye_enabled = true`
43
+ `config.inboxes.faye_host = "inboxes-app.dev" # localhost by default`
44
+ `config.inboxes.faye_port = 9292 # 9292 by default`
49
45
 
50
46
  5. Faye installation is finished. If you have any troubles, check the [example app](https://github.com/kirs/inboxes-app/)
51
47
 
@@ -4,4 +4,10 @@ class Inboxes::BaseController < ApplicationController
4
4
  def init_discussion
5
5
  @discussion = Discussion.find(params[:discussion_id])
6
6
  end
7
+
8
+ # Needs to be overriden so that we use Spree's Ability rather than anyone else's.
9
+ def current_ability
10
+ # raise "Loading Ability"
11
+ @current_ability ||= Inboxes::Ability.new(current_user)
12
+ end
7
13
  end
@@ -48,8 +48,8 @@ class Inboxes::DiscussionsController < Inboxes::BaseController
48
48
  # end
49
49
 
50
50
  def load_and_check_discussion_recipient
51
- # initializing model fir new and create actions
52
- @discussion = Discussion.new((params[:discussion] ? params[:discussion] : {}))
51
+ # initializing model for new and create actions
52
+ @discussion = Discussion.new(params[:discussion].presence || {})
53
53
  # @discussion.recipient_tokens = params[:recipients] if params[:recipients] # pre-population
54
54
 
55
55
  # checking if discussion with this user already exists
@@ -0,0 +1,38 @@
1
+ # Implementation class for Cancan gem. Instead of overriding this class, consider adding new permissions
2
+ # using the special +register_ability+ method which allows extensions to add their own abilities.
3
+ #
4
+ # See http://github.com/ryanb/cancan for more details on cancan.
5
+ module Inboxes
6
+ class Ability
7
+ include CanCan::Ability
8
+
9
+ class_attribute :abilities
10
+ self.abilities = Set.new
11
+
12
+ # Allows us to go beyond the standard cancan initialize method which makes it difficult for engines to
13
+ # modify the default +Ability+ of an application. The +ability+ argument must be a class that includes
14
+ # the +CanCan::Ability+ module. The registered ability should behave properly as a stand-alone class
15
+ # and therefore should be easy to test in isolation.
16
+ def self.register_ability(ability)
17
+ self.abilities.add(ability)
18
+
19
+ end
20
+
21
+ def initialize(user)
22
+ # raise "Initializing 3rd patry"
23
+ # self.clear_aliased_actions
24
+
25
+ # can [:index, :create], Discussion
26
+ # can :read, Discussion do |discussion|
27
+ # discussion.can_participate?(user)
28
+ # end
29
+
30
+ #include any abilities registered by extensions, etc.
31
+
32
+ Ability.abilities.each do |clazz|
33
+ ability = clazz.send(:new, user)
34
+ @rules = rules + ability.send(:rules)
35
+ end
36
+ end
37
+ end
38
+ end
data/inboxes.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  # specify any dependencies here; for example:
22
22
  # s.add_development_dependency "ruby-debug"
23
23
  s.add_runtime_dependency "haml-rails"
24
- s.add_runtime_dependency "cancan"
24
+ s.add_runtime_dependency "cancan", ['>= 0']
25
25
  # s.add_runtime_dependency "inherited_resources"
26
26
 
27
27
  # s.add_development_dependency 'dm-sqlite-adapter', ['>= 1.1.0']
data/lib/inboxes.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  require "inboxes/version"
2
2
  require "inboxes/railtie"
3
+ require "inboxes/ability"
3
4
  require "inboxes/engine"
4
5
  require "inboxes/active_record_extension"
5
6
 
7
+
6
8
  module Inboxes
7
9
 
8
10
  def self.configure(&block)
@@ -1,9 +1,13 @@
1
+ require "cancan"
2
+
1
3
  module Inboxes
2
4
  class InboxesAbility
3
- include CanCan::Ability
5
+ include ::CanCan::Ability
4
6
 
5
7
  def initialize(user)
6
8
  # Discussion
9
+ # raise "Registered!"
10
+
7
11
  can [:index, :create], Discussion
8
12
  can :read, Discussion do |discussion|
9
13
  discussion.can_participate?(user)
@@ -2,8 +2,15 @@ require "inboxes/ability"
2
2
 
3
3
  module Inboxes
4
4
  class Engine < ::Rails::Engine
5
+ # raise "Engine Activated"
5
6
  def self.activate
6
7
  Ability.register_ability(InboxesAbility)
8
+ # raise "Activated"
7
9
  end
10
+
11
+ def load_tasks
12
+ end
13
+
14
+ config.to_prepare &method(:activate).to_proc
8
15
  end
9
16
  end
@@ -1,4 +1,5 @@
1
1
  require 'rails'
2
+ require "inboxes/ability"
2
3
 
3
4
  module Inboxes
4
5
  class Railtie < ::Rails::Railtie
@@ -14,5 +15,9 @@ module Inboxes
14
15
 
15
16
  # app.config.middleware.insert_before "::Rails::Rack::Logger", "Inboxes::Middleware"
16
17
  end
18
+
19
+ # def self.activate
20
+ # Ability.register_ability(InboxesAbility)
21
+ # end
17
22
  end
18
23
  end
@@ -1,3 +1,3 @@
1
1
  module Inboxes
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inboxes
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kir Shatrov
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-17 00:00:00 Z
18
+ date: 2011-11-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: haml-rails
@@ -107,6 +107,7 @@ files:
107
107
  - app/controllers/inboxes/speakers_controller.rb
108
108
  - app/helpers/inboxes_helper.rb
109
109
  - app/models/discussion.rb
110
+ - app/models/inboxes/ability.rb
110
111
  - app/models/message.rb
111
112
  - app/models/speaker.rb
112
113
  - app/views/inboxes/discussions/_form.html.haml