strong-permitter 0.0.1

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: d99ce8089a7014eb095030a03317bc42e9849c19
4
+ data.tar.gz: d22a533b2d42676459a9745269931e3a9b1ebf87
5
+ SHA512:
6
+ metadata.gz: e8205fe8c40eb001221101a8c8f17e3febd844eb83a3ffecb7387ab59af457e03077950c97b53278f11f8bc6a9ca915e1ae1390fd9db636212ed3eb67b812d67
7
+ data.tar.gz: d87b412d995e6471da806b5a6a7582ca9e2d440655dac743a93459d75f26da249474de6a1047ec676829b967a4403237ac794209c375c8c55d2db8a44228ffb9
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea/
16
+ .ruby-version
17
+ .ruby-gemset
18
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in strong_permitter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 evg2108
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,87 @@
1
+ # StrongPermitter
2
+
3
+ This gem allows move params permissions from controllers to separated permission-objects.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'strong-permitter'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ Before you start using permission-objects, you need integrate StrongPermitter::Manager to your controllers.
20
+ For this, you may execute console command, which create file strong_permitter.rb in initializers directory:
21
+
22
+ $ strong_permitter install
23
+
24
+ Or you may include StrongPermitter::Manager into ApplicationController:
25
+
26
+ ```ruby
27
+ class ApplicationController < ActionController::Base
28
+ include StrongPermitter::Manager
29
+ end
30
+ ```
31
+
32
+ For define permission-object you should create ruby file in `app/controllers/permissions` directory.
33
+ File name should match with controller. For `ArticlesController` permission-object file name should be `articles_permission.rb`.
34
+
35
+ Permission-object code:
36
+
37
+ ```ruby
38
+ class ArticlesPermission < StrongPermitter::Permission::Base
39
+
40
+ # standard actions permission
41
+ create_params :title, :content, :author_name
42
+ update_params :content
43
+
44
+ # for non-standard actions permissions use:
45
+ # allowed_params_for :action_name, :param1, :param2, ...
46
+ allowed_params_for :activate_article, :activation_status
47
+ end
48
+ ```
49
+
50
+ After that, you may use `permitted_params` method for your action methods:
51
+
52
+ ```ruby
53
+ class ArticlesController < ApplicationController
54
+ def update
55
+ @article = Article.find(params[:id])
56
+ if @article.update_attributes(permitted_params)
57
+ # ...
58
+ else
59
+ # ...
60
+ end
61
+ end
62
+
63
+ def create
64
+ @article = Article.new(permitted_params)
65
+ if @article.save
66
+ # ...
67
+ else
68
+ # ...
69
+ end
70
+ end
71
+
72
+ # non-standard action
73
+ def activate_article
74
+ @article = Article.find(params[:id])
75
+ @article.update_attributes(permitted_params)
76
+ # ...
77
+ end
78
+ end
79
+ ```
80
+
81
+ ## Contributing
82
+
83
+ 1. Fork it ( https://github.com/evg2108/strong-permitter/fork )
84
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
85
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
86
+ 4. Push to the branch (`git push origin my-new-feature`)
87
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Exit cleanly from an early interrupt
4
+ Signal.trap("INT") { exit 1 }
5
+
6
+ require 'strong_permitter'
7
+ require 'strong_permitter/cli'
8
+
9
+ StrongPermitter::Cli.start(*ARGV)
@@ -0,0 +1,13 @@
1
+ require 'strong_permitter/version'
2
+ require 'strong_permitter/manager'
3
+ require 'strong_permitter/permission/base'
4
+
5
+ if defined? Rails
6
+ module StrongPermitter
7
+ class Railtie < ::Rails::Railtie
8
+ initializer 'strong-permitter.autoload', :before => :set_autoload_paths do |app|
9
+ app.config.autoload_paths += %W(#{Rails.root}/app/controllers/permissions)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,34 @@
1
+ module StrongPermitter
2
+ class Cli
3
+ def self.start(*args)
4
+ if args.length != 1
5
+ puts "Unknown command format. Please use 'strong_permitter -h' for more information."
6
+ return
7
+ end
8
+
9
+ case args.first
10
+ when '--help', '-h'
11
+ puts 'Commands format: strong_permitter <command>'
12
+ puts 'Available commands:'
13
+ puts "\tinstall\t- Create initializer for Rails application"
14
+ when 'install'
15
+ print 'Creating config/initializers/strong_permitter.rb'
16
+ if File.exist?('config/initializers/strong_permitter.rb')
17
+ puts "\t(already exist - skipped)"
18
+ else
19
+ FileUtils.cp(File.expand_path('../templates/initializer.rb', __FILE__), 'config/initializers/strong_permitter.rb')
20
+ puts "\t(ok)"
21
+ end
22
+
23
+ print 'Making directory app/controllers/permissions'
24
+ if Dir.exist?('app/controllers/permissions')
25
+ puts "\t\t(already exist - skipped)"
26
+ else
27
+ FileUtils.mkpath 'app/controllers/permissions'
28
+ puts "\t\t(ok)"
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,13 @@
1
+ module StrongPermitter
2
+ module Manager
3
+ def permitted_params
4
+ permission_class = "#{self.class.name.sub('Controller', '')}Permission".camelcase.safe_constantize
5
+ return nil unless permission_class
6
+
7
+ resource_name = permission_class.resource_name || controller_name.singularize
8
+ allowed_attributes = permission_class.actions[action_name]
9
+
10
+ params.require(resource_name).permit(allowed_attributes)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ module StrongPermitter
2
+ module Permission
3
+ class Base
4
+ class << self
5
+ def actions
6
+ @actions ||= HashWithIndifferentAccess.new { |hash,val| hash[val] = [] }
7
+ end
8
+
9
+ def create_params(*param_names)
10
+ allowed_params_for :create, *param_names
11
+ end
12
+
13
+ def update_params(*param_names)
14
+ allowed_params_for :update, *param_names
15
+ end
16
+
17
+ def allowed_params_for(action_name, *param_names)
18
+ actions[action_name] = param_names
19
+ end
20
+
21
+ def resource_name=(name)
22
+ @resource_name ||= name
23
+ end
24
+
25
+ def resource_name
26
+ @resource_name
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ class ActionController::Base
2
+ include StrongPermitter::Manager
3
+ end
@@ -0,0 +1,3 @@
1
+ module StrongPermitter
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'strong_permitter/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'strong-permitter'
7
+ spec.version = StrongPermitter::VERSION
8
+ spec.authors = %w(evg2108)
9
+ spec.email = %w(evg2108@yandex.ru)
10
+ spec.summary = %q{It allows move params permissions from controllers to separated permission-objects}
11
+ spec.description = %q{It allows move params permissions from controllers to separated permission-objects}
12
+ spec.homepage = 'https://github.com/evg2108/strong-permitter'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
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 = %w(lib)
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.7'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ spec.add_dependency 'actionpack', '~> 4.0'
23
+ spec.add_dependency 'railties', '~> 4.0'
24
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: strong-permitter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - evg2108
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-19 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: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: actionpack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: railties
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ description: It allows move params permissions from controllers to separated permission-objects
70
+ email:
71
+ - evg2108@yandex.ru
72
+ executables:
73
+ - strong_permitter
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/strong_permitter
83
+ - lib/strong-permitter.rb
84
+ - lib/strong_permitter/cli.rb
85
+ - lib/strong_permitter/manager.rb
86
+ - lib/strong_permitter/permission/base.rb
87
+ - lib/strong_permitter/templates/initializer.rb
88
+ - lib/strong_permitter/version.rb
89
+ - strong-permitter.gemspec
90
+ homepage: https://github.com/evg2108/strong-permitter
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: It allows move params permissions from controllers to separated permission-objects
114
+ test_files: []