guarda 0.1.0 → 0.4.0

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
  SHA256:
3
- metadata.gz: f15e288362775a5372998f48ab4a1dd3341c943cb0f61a1ffef7f8e7c6651dfe
4
- data.tar.gz: 13e8ca73c3e09f446fa15d4064ee69feda99f401ab7a63c4e5ca99aee97fb6bc
3
+ metadata.gz: 8ffe343cd6f4cd51a1b384fdb4e1299d14960e574a60fd2ef7e5d03298563289
4
+ data.tar.gz: 60096b5bd502a631c19b5df0a028fd2e4d96828645da9409f47a53f19ea74b95
5
5
  SHA512:
6
- metadata.gz: 1335b5450f75bb16742b8255bce42a7e21b8c704b3b3d53fee5a1da6fb00f4de352b7d568a4d324993755412c4435666d6226c444a0831a5b8c17f66f2457cc9
7
- data.tar.gz: edcf1d6ad4b4b58a4e26a9c522af2b54b6c85770af54e59f316bea96517a094de9741af5593caaf2b165e02524ef1135945ec2bade377bdd927915c52f753e69
6
+ metadata.gz: 6b1b618a33b3b7a27322cad51b872af9aca19d3d309dbeaf3004112e82b808c859bab5e4c688be6d6f0d98e6ef5ec4359f7573e464e105e8a64563b7d12e2170
7
+ data.tar.gz: 01bea2ae2c82935e7cfead682f1cedcee50ccace4810b14e1f5f4f5cfbb0d3e20f85fe19eaceccfb904693480c77d1e429e405c26ebcbc3f8da18366f79507fc
data/README.md CHANGED
@@ -1,34 +1,70 @@
1
1
  # Guarda
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ Is another authorization gem that was heavily inspired by [Pundit](https://rubygems.org/gems/pundit).
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/guarda`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ It assumes you are using [Current Attributes](https://api.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html) to get your currently authenticated user.
6
6
 
7
7
  ## Installation
8
8
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
9
  Install the gem and add to the application's Gemfile by executing:
12
10
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
11
+ ```bash
12
+ bundle add guarda
13
+ ```
14
14
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
15
+ Include `Guarda::Authorization` in your application controller:
16
16
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
17
+ ```ruby
18
+ class ApplicationController < ActionController::Base
19
+ include Guarda::Authorization
20
+ end
21
+ ```
18
22
 
19
23
  ## Usage
20
24
 
21
- TODO: Write usage instructions here
22
-
23
- ## Development
24
-
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
-
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
-
29
- ## Contributing
30
-
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/guarda.
25
+ In the controller:
26
+
27
+ ```ruby
28
+ class PostsController < ApplicationController
29
+ def index
30
+ authorize
31
+ end
32
+
33
+ def update
34
+ authorize @post
35
+ end
36
+ end
37
+ ```
38
+
39
+ In the view:
40
+
41
+ ```erb
42
+ <% if policy("posts").index? %>
43
+ <%= link_to "Posts", "#" %>
44
+ <% end %>
45
+
46
+ <% if policy("posts", @post).update? %>
47
+ <%= link_to "Edit Post", "#" %>
48
+ <% end %>
49
+ ```
50
+
51
+ With this policy class `app/policies/posts_policy.rb`:
52
+
53
+ ```ruby
54
+ class PostsPolicy
55
+ def initialize(post = nil)
56
+ @post = post
57
+ end
58
+
59
+ def index?
60
+ Current.person.admin?
61
+ end
62
+
63
+ def update?
64
+ @post.author == Current.person
65
+ end
66
+ end
67
+ ```
32
68
 
33
69
  ## License
34
70
 
data/guarda.gemspec CHANGED
@@ -9,9 +9,9 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["abdul@hey.com"]
10
10
 
11
11
  spec.summary = "Another authorization gem"
12
- spec.homepage = "https://wwww.guidedrails.com"
12
+ spec.homepage = "https://www.guidedrails.com"
13
13
  spec.license = "MIT"
14
- spec.required_ruby_version = ">= 2.6.0"
14
+ spec.required_ruby_version = ">= 3.1.0"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
17
  spec.metadata["source_code_uri"] = "https://github.com/Guided-Rails/guarda"
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_development_dependency "activesupport"
31
- spec.add_development_dependency "minitest-reporters"
30
+ spec.add_development_dependency "activesupport", "~> 7.1", ">= 7.1.3"
31
+ spec.add_development_dependency "minitest-reporters", "~> 1.6", ">= 1.6.1"
32
32
  end
@@ -10,7 +10,7 @@ module Guarda
10
10
  end
11
11
  end
12
12
 
13
- def authorize(controller: nil, query: nil, record: nil)
13
+ def authorize(record = nil, controller: nil, query: nil)
14
14
  @_authorization_performed = true
15
15
  controller ||= controller_path
16
16
  query ||= "#{action_name}?"
@@ -19,7 +19,7 @@ module Guarda
19
19
  raise(NotAuthorizedError, self.class)
20
20
  end
21
21
 
22
- def policy(controller, record)
22
+ def policy(controller, record = nil)
23
23
  PolicyFinder.find(controller).new(record)
24
24
  end
25
25
 
@@ -23,7 +23,7 @@ module Guarda
23
23
  end
24
24
 
25
25
  def policy_class_name
26
- controller_name.camelize.concat("Policy")
26
+ controller_name.to_s.camelize.concat("Policy")
27
27
  end
28
28
  end
29
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Guarda
4
- VERSION = "0.1.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,43 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guarda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdullah Hashim
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-28 00:00:00.000000000 Z
11
+ date: 2024-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '7.1'
17
20
  - - ">="
18
21
  - !ruby/object:Gem::Version
19
- version: '0'
22
+ version: 7.1.3
20
23
  type: :development
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '7.1'
24
30
  - - ">="
25
31
  - !ruby/object:Gem::Version
26
- version: '0'
32
+ version: 7.1.3
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: minitest-reporters
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.6'
31
40
  - - ">="
32
41
  - !ruby/object:Gem::Version
33
- version: '0'
42
+ version: 1.6.1
34
43
  type: :development
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.6'
38
50
  - - ">="
39
51
  - !ruby/object:Gem::Version
40
- version: '0'
52
+ version: 1.6.1
41
53
  description:
42
54
  email:
43
55
  - abdul@hey.com
@@ -54,11 +66,11 @@ files:
54
66
  - lib/guarda/policy_finder.rb
55
67
  - lib/guarda/version.rb
56
68
  - sig/guarda.rbs
57
- homepage: https://wwww.guidedrails.com
69
+ homepage: https://www.guidedrails.com
58
70
  licenses:
59
71
  - MIT
60
72
  metadata:
61
- homepage_uri: https://wwww.guidedrails.com
73
+ homepage_uri: https://www.guidedrails.com
62
74
  source_code_uri: https://github.com/Guided-Rails/guarda
63
75
  post_install_message:
64
76
  rdoc_options: []
@@ -68,7 +80,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
80
  requirements:
69
81
  - - ">="
70
82
  - !ruby/object:Gem::Version
71
- version: 2.6.0
83
+ version: 3.1.0
72
84
  required_rubygems_version: !ruby/object:Gem::Requirement
73
85
  requirements:
74
86
  - - ">="