know_it_all 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 633cbb98f1604939c8ee0d84bfe5ac3b0bb90c34
4
- data.tar.gz: bd87e1c451a6086f86e45c068660fa7f6fcfb503
3
+ metadata.gz: bb53cc98993d4343b3ace8c80f84cbe790bc5b3d
4
+ data.tar.gz: 7b51c78b30fd2fd9ba90fbf5093ac0e325ef5cf1
5
5
  SHA512:
6
- metadata.gz: 5836a2802dcc9ae4e6b51dfb0473cb6243676ea6e92e59e467fb89d76034bdae4bd321fdbea4138394e21903a3c479fb2d6ff8f5e8be6c79ce81ff65ccdc2cdc
7
- data.tar.gz: 840a67e545be103fbe3f59fe97653b1659ebb6e0dfd130f6be062d29360a7e20ae61cb74458ba9daf4b5852d2549996658b8f7a066045356d6a41bd09a870a2b
6
+ metadata.gz: 5043002c2982d319e9ba9917b559a5bf6aba290e0007af569d3f7809ce6b8141519e73ecae17f48c856b1711f3a642995df6e318054f58b88f95c15e8f8e3eb6
7
+ data.tar.gz: e7dbc212819b30bbf4c2b121c81f4cd1b446add74c0c04631c6f2559ad282fcd533089547d0b044c86f900ec3ea4cab751a56bb62cdf6513d92cf78ae0cef0a8
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  # KnowItAll
4
4
 
5
+ [![Join the chat at https://gitter.im/mrodrigues/know_it_all](https://badges.gitter.im/mrodrigues/know_it_all.svg)](https://gitter.im/mrodrigues/know_it_all?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6
+
5
7
  KnowItAll is a small, object-oriented approach to authorization. It knows everything about your application!
6
8
 
7
9
  More of an architectural pattern for API-focused authorization than properly a dependency, and heavily inspired by [Pundit](https://github.com/elabs/pundit), this gem simply provides a small set of helpers that make applying the pattern easier.
data/know_it_all.gemspec CHANGED
@@ -19,8 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "activesupport"
23
-
24
22
  spec.add_development_dependency "bundler", "~> 1.10"
25
23
  spec.add_development_dependency "rake", "~> 10.0"
26
24
  spec.add_development_dependency "minitest"
data/lib/know_it_all.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "know_it_all/version"
2
2
  require "know_it_all/base"
3
3
  require "know_it_all/authorizer"
4
+ require "know_it_all/string_helper"
4
5
 
5
6
  module KnowItAll
6
7
  SUFFIX = "Policies"
@@ -32,14 +33,14 @@ module KnowItAll
32
33
  end
33
34
 
34
35
  def policy_class(policy_name: self.policy_name)
35
- @policy_class ||= policy_name.constantize
36
+ @policy_class ||= self.class.const_get(policy_name)
36
37
  end
37
38
 
38
39
  def policy_name(
39
40
  controller_path: self.controller_path,
40
41
  action_name: self.action_name
41
42
  )
42
- "#{controller_path.to_s.camelize}#{SUFFIX}::#{action_name.to_s.camelize}"
43
+ "#{KnowItAll::StringHelper.classify(controller_path)}#{SUFFIX}::#{KnowItAll::StringHelper.classify(action_name)}"
43
44
  end
44
45
 
45
46
  def render_not_authorized(exception)
@@ -0,0 +1,36 @@
1
+ # Extracted from hanami-utils:
2
+ # https://github.com/hanami/utils/blob/3d7aa877182a545654b2ebd3a2a495546051ac91/lib/hanami/utils/string.rb
3
+
4
+ module KnowItAll
5
+ class StringHelper
6
+ EMPTY_STRING = ''.freeze
7
+ UNDERSCORE_DIVISION_TARGET = '\1_\2'.freeze
8
+ NAMESPACE_SEPARATOR = '::'.freeze
9
+ CLASSIFY_SEPARATOR = '_'.freeze
10
+ UNDERSCORE_SEPARATOR = '/'.freeze
11
+ DASHERIZE_SEPARATOR = '-'.freeze
12
+
13
+ CLASSIFY_WORD_SEPARATOR = /#{CLASSIFY_SEPARATOR}|#{NAMESPACE_SEPARATOR}|#{UNDERSCORE_SEPARATOR}|#{DASHERIZE_SEPARATOR}/
14
+
15
+ def self.classify(string)
16
+ string = string.to_s
17
+
18
+ words = underscore(string).split(CLASSIFY_WORD_SEPARATOR).map!(&:capitalize)
19
+ delimiters = string.scan(CLASSIFY_WORD_SEPARATOR)
20
+
21
+ delimiters.map! do |delimiter|
22
+ delimiter == CLASSIFY_SEPARATOR ? EMPTY_STRING : NAMESPACE_SEPARATOR
23
+ end
24
+
25
+ words.zip(delimiters).join
26
+ end
27
+
28
+ def self.underscore(string)
29
+ new_string = string.gsub(NAMESPACE_SEPARATOR, UNDERSCORE_SEPARATOR)
30
+ new_string.gsub!(/([A-Z\d]+)([A-Z][a-z])/, UNDERSCORE_DIVISION_TARGET)
31
+ new_string.gsub!(/([a-z\d])([A-Z])/, UNDERSCORE_DIVISION_TARGET)
32
+ new_string.gsub!(/[[:space:]]|\-/, UNDERSCORE_DIVISION_TARGET)
33
+ new_string.downcase
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module KnowItAll
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: know_it_all
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - mrodrigues
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-30 00:00:00.000000000 Z
11
+ date: 2016-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +100,7 @@ files:
114
100
  - lib/know_it_all.rb
115
101
  - lib/know_it_all/authorizer.rb
116
102
  - lib/know_it_all/base.rb
103
+ - lib/know_it_all/string_helper.rb
117
104
  - lib/know_it_all/version.rb
118
105
  homepage: https://github.com/mrodrigues/know_it_all
119
106
  licenses: