scoped_rolify 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: deaaabae41d436b0c393ceb4ecb219d420163d97
4
+ data.tar.gz: 6b8e3f4dfadf46dbd23bc12bcc7548845a62390d
5
+ SHA512:
6
+ metadata.gz: e6e5906f5c4bd2c4d87f4543f18a227d3ffb5d7cee36c91dad8e71a4f1457263026fb531d720a4b099aa0689577cf56615b7f1e86d417c2adabae981c2aa1d4d
7
+ data.tar.gz: 566ae4ca33bd94717c6df4082803ee1f256b7228002d1e54d12aa6339ddcc82d2b853935029ed368fc287de4cafb4b3ada9b5d8c23f614be66c768554b681916
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ repo_token: GErR5C0zFnYNumgFd8UUE5LTq8w0ggvr4
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ scopable
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p353
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ### VERSION 0.0.1
2
+
3
+ * Resctricted add_role method
4
+ * Resctricted with_role method
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in scoped_rolify.gemspec
4
+ gemspec
5
+
6
+ ENV['ADAPTER'] ||= 'active_record'
7
+
8
+ group :test do
9
+ case ENV['ADAPTER']
10
+ when nil, 'active_record'
11
+ gem 'sqlite3', platform: 'ruby'
12
+ gem 'activerecord', '>= 3.2.0', require: 'active_record'
13
+ else
14
+ raise "Unknown model adapter: #{ENV['ADAPTER']}"
15
+ end
16
+
17
+ gem 'pry'
18
+ gem 'coveralls', require: false
19
+ end
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec, cmd: 'rspec --color --fail-fast' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Joel AZEMAR
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # ScopedRolify
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/scoped_rolify.png)](http://badge.fury.io/rb/scoped_rolify)
4
+
5
+ [![Code Climate](https://codeclimate.com/github/joel/scoped_rolify.png)](https://codeclimate.com/github/joel/scoped_rolify)
6
+
7
+ [![Dependency Status](https://gemnasium.com/joel/scoped_rolify.png)](https://gemnasium.com/joel/scoped_rolify)
8
+
9
+ [![Build Status](https://travis-ci.org/joel/scoped_rolify.png?branch=master)](https://travis-ci.org/joel/scoped_rolify) (Travis CI)
10
+
11
+ [![Coverage Status](https://coveralls.io/repos/joel/scoped_rolify/badge.png)](https://coveralls.io/r/joel/scoped_rolify)
12
+
13
+ This is a monkey patch of rolify for specifics purposes. We want only have users scoped on specific instance of resource. We are no really interesting by hierarchy.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ gem 'scoped_rolify'
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install scoped_rolify
28
+
29
+ ## Usage
30
+
31
+ Method #add_scope_role map #add_role
32
+
33
+ You can not add right without instance of resource
34
+
35
+ user = User.find(1)
36
+ user.add_scope_role :admin # Thrown MissingResourceError
37
+ user.add_scope_role :moderator, Forum # Thrown InstanceResourceError
38
+
39
+ Only this case it's possible
40
+
41
+ user.add_scope_role :moderator, Forum.first #
42
+
43
+ Method with_scoped_role map #with_role
44
+
45
+ You can not call method without instance of resource
46
+
47
+ User.with_scoped_role :admin # Thrown MissingResourceError
48
+ User.with_scoped_role :moderator, Forum # Thrown InstanceResourceError
49
+
50
+ Only this case it's possible
51
+
52
+ User.with_scoped_role :moderator, Forum.first #
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it ( http://github.com/<my-github-username>/scoped_rolify/fork )
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ RSpec::Core::RakeTask.new('spec:progress') do |spec|
10
+ spec.rspec_opts = %w(--format progress)
11
+ spec.pattern = 'spec/**/*_spec.rb'
12
+ end
13
+
14
+ task default: :spec
15
+
data/bin/publish ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # bin/publish 0.0.1
4
+
5
+ class Publish
6
+
7
+ def start version
8
+ system "bundle && bundle exec rspec"
9
+ system "gem build scoped_rolify.gemspec"
10
+ system "git tag -a v#{version} -m 'version #{version}'"
11
+ system "git push --tags"
12
+ system "gem push scoped_rolify-#{version}.gem"
13
+ system "git push origin master"
14
+ end
15
+
16
+ end
17
+
18
+ if ARGV.length != 1 # or !ARGV[0].match(/\d{1,3}.\d{1,3}.\d{1,3}/)
19
+ puts 'HELP: '
20
+ puts '$ bin/publish 0.0.1'
21
+ exit 0
22
+ end
23
+
24
+ Publish.new.start ARGV[0]
@@ -0,0 +1,12 @@
1
+ require 'rolify'
2
+
3
+ require 'scoped_rolify/version'
4
+ require 'scoped_rolify/role'
5
+ require 'scoped_rolify/finders'
6
+
7
+ class MissingResourceError < StandardError; end
8
+ class InstanceResourceError < StandardError; end
9
+
10
+ module ScopedRolify
11
+ # Your code goes here...
12
+ end
@@ -0,0 +1,11 @@
1
+ module Rolify
2
+ module Finders
3
+
4
+ def with_scoped_role(role_name, resource)
5
+ raise MissingResourceError, "You should provide resource" unless resource
6
+ raise InstanceResourceError, "You should provide INSTANCE resource" unless resource.respond_to?(:id)
7
+
8
+ with_role(role_name, resource)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Rolify
2
+ module Role
3
+
4
+ def add_scope_role(role_name, resource)
5
+ raise MissingResourceError, 'You should provide resource' unless resource
6
+ raise InstanceResourceError, 'You should provide INSTANCE resource' unless resource.respond_to?(:id)
7
+
8
+ add_role(role_name, resource)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module ScopedRolify
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'scoped_rolify/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'scoped_rolify'
7
+ spec.version = ScopedRolify::VERSION
8
+ spec.authors = ['Joel AZEMAR']
9
+ spec.email = ['joel.azemar@gmail.com']
10
+ spec.summary = %q{This is a monkey patch of rolify}
11
+ spec.description = %q{This is a monkey patch of rolify, and add new methods}
12
+ spec.homepage = 'https://github.com/joel/scoped_rolify'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'rolify', '~> 3.4'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.5'
23
+ spec.add_development_dependency 'rake', '~> 10.1'
24
+ spec.add_development_dependency 'rspec', '~> 2.14'
25
+ spec.add_development_dependency 'rspec-rails', '~> 2.14'
26
+
27
+ spec.required_ruby_version = '~> 2.0'
28
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rolify::Finders do
4
+ let(:resource) { Forum.first }
5
+ let(:user) { User.first }
6
+
7
+ before { user.add_role(:admin, resource) }
8
+
9
+ subject { User }
10
+
11
+ it { expect { subject.with_scoped_role(:admin, Forum) }.to raise_error InstanceResourceError }
12
+ it { expect { subject.with_scoped_role(:admin, resource) }.to_not raise_error }
13
+
14
+ context 'regular way' do
15
+ it { User.with_scoped_role(:admin, resource).should eq([user]) }
16
+ end
17
+
18
+ end
19
+
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rolify::Role do
4
+ let(:instance) { Forum.first }
5
+
6
+ subject { User.first }
7
+
8
+ it { expect { subject.add_scope_role(:admin, Forum) }.to raise_error InstanceResourceError }
9
+ it { expect { subject.add_scope_role(:admin, instance) }.to_not raise_error }
10
+
11
+ context 'regular way' do
12
+ before { subject.add_scope_role(:admin, instance) }
13
+ it { should have_role :admin, instance }
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,3 @@
1
+ require 'spec_helper'
2
+
3
+ describe ScopedRolify
@@ -0,0 +1,18 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'rolify'
4
+ require 'scoped_rolify'
5
+ require 'rails'
6
+
7
+ require 'coveralls'
8
+ Coveralls.wear!
9
+
10
+ ENV['ADAPTER'] ||= 'active_record'
11
+
12
+ load File.dirname(__FILE__) + "/support/adapters/#{ENV['ADAPTER']}.rb"
13
+ load File.dirname(__FILE__) + '/support/data.rb'
14
+
15
+ RSpec.configure do |c|
16
+ c.run_all_when_everything_filtered = true
17
+ end
18
+
@@ -0,0 +1,23 @@
1
+ require 'active_record'
2
+
3
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
4
+ ActiveRecord::Base.extend Rolify
5
+
6
+ load File.dirname(__FILE__) + '/../schema.rb'
7
+
8
+ # Standard user and role classes
9
+ class User < ActiveRecord::Base
10
+ rolify
11
+ end
12
+
13
+ class Role < ActiveRecord::Base
14
+ has_and_belongs_to_many :users, join_table: :users_roles
15
+ belongs_to :resource, polymorphic: true
16
+
17
+ extend Rolify::Adapter::Scopes
18
+ end
19
+
20
+ # Resources classes
21
+ class Forum < ActiveRecord::Base
22
+ #resourcify done during specs setup to be able to use custom user classes
23
+ end
@@ -0,0 +1,9 @@
1
+ # Users
2
+ User.destroy_all
3
+ User.create login: 'admin'
4
+
5
+ # Roles
6
+ Role.destroy_all
7
+
8
+ # Resources
9
+ Forum.create name: 'forum 1'
@@ -0,0 +1,23 @@
1
+ ActiveRecord::Schema.define do
2
+ self.verbose = false
3
+
4
+ create_table(:users) do |t|
5
+ t.string :login
6
+ end
7
+
8
+ create_table(:roles) do |t|
9
+ t.string :name
10
+ t.references :resource, polymorphic: true
11
+ t.timestamps
12
+ end
13
+
14
+ create_table(:users_roles, :id => false) do |t|
15
+ t.references :user
16
+ t.references :role
17
+ end
18
+
19
+ create_table(:forums) do |t|
20
+ t.string :name
21
+ end
22
+
23
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scoped_rolify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Joel AZEMAR
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rolify
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.14'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.14'
83
+ description: This is a monkey patch of rolify, and add new methods
84
+ email:
85
+ - joel.azemar@gmail.com
86
+ executables:
87
+ - publish
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".coveralls.yml"
92
+ - ".gitignore"
93
+ - ".ruby-gemset"
94
+ - ".ruby-version"
95
+ - ".travis.yml"
96
+ - CHANGELOG.md
97
+ - Gemfile
98
+ - Guardfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - bin/publish
103
+ - lib/scoped_rolify.rb
104
+ - lib/scoped_rolify/finders.rb
105
+ - lib/scoped_rolify/role.rb
106
+ - lib/scoped_rolify/version.rb
107
+ - scoped_rolify.gemspec
108
+ - spec/scoped_rolify/finders_spec.rb
109
+ - spec/scoped_rolify/role_spec.rb
110
+ - spec/scoped_rolify_spec.rb
111
+ - spec/spec_helper.rb
112
+ - spec/support/adapters/active_record.rb
113
+ - spec/support/data.rb
114
+ - spec/support/schema.rb
115
+ homepage: https://github.com/joel/scoped_rolify
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - "~>"
126
+ - !ruby/object:Gem::Version
127
+ version: '2.0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.2.2
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: This is a monkey patch of rolify
139
+ test_files:
140
+ - spec/scoped_rolify/finders_spec.rb
141
+ - spec/scoped_rolify/role_spec.rb
142
+ - spec/scoped_rolify_spec.rb
143
+ - spec/spec_helper.rb
144
+ - spec/support/adapters/active_record.rb
145
+ - spec/support/data.rb
146
+ - spec/support/schema.rb