guarda 0.0.0 → 0.1.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: 37fb9b774cc00795bf96edc8655287433b68c4f9f1b95f146cfd28936a887343
4
- data.tar.gz: 4a94650d4778d42c8104294f0193b3621f0f7b07c11d0d3c5cf12c156153928b
3
+ metadata.gz: f15e288362775a5372998f48ab4a1dd3341c943cb0f61a1ffef7f8e7c6651dfe
4
+ data.tar.gz: 13e8ca73c3e09f446fa15d4064ee69feda99f401ab7a63c4e5ca99aee97fb6bc
5
5
  SHA512:
6
- metadata.gz: a0d29b1ae0d34a9bfa5f2c2bbc5cc076a55d8b394495ef886cb6348e4887740287fae4ba862d4b5536095ac37f4ff04e8309940113f1aea2836224843dc26c3c
7
- data.tar.gz: 46843ee2edf9e91337c0828d2a1451f324160f857542cbad424a9a4a290730ff8ecb14deb07b6d231a14bf77f86bfdc5e3e9554d405879b6683fcb75eb4bd76c
6
+ metadata.gz: 1335b5450f75bb16742b8255bce42a7e21b8c704b3b3d53fee5a1da6fb00f4de352b7d568a4d324993755412c4435666d6226c444a0831a5b8c17f66f2457cc9
7
+ data.tar.gz: edcf1d6ad4b4b58a4e26a9c522af2b54b6c85770af54e59f316bea96517a094de9741af5593caaf2b165e02524ef1135945ec2bade377bdd927915c52f753e69
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Abdullah Hashim
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Guarda
2
+
3
+ TODO: Delete this and the text below, and describe your gem
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.
6
+
7
+ ## Installation
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
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
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.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ task default: :test
data/guarda.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/guarda/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "guarda"
7
+ spec.version = Guarda::VERSION
8
+ spec.authors = ["Abdullah Hashim"]
9
+ spec.email = ["abdul@hey.com"]
10
+
11
+ spec.summary = "Another authorization gem"
12
+ spec.homepage = "https://wwww.guidedrails.com"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/Guided-Rails/guarda"
18
+
19
+ spec.files = Dir.chdir(__dir__) do
20
+ `git ls-files -z`.split("\x0").reject do |f|
21
+ (File.expand_path(f) == __FILE__) ||
22
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
23
+ end
24
+ end
25
+
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "activesupport"
31
+ spec.add_development_dependency "minitest-reporters"
32
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Guarda
4
+ module Authorization
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ if respond_to?(:helper_method)
9
+ helper_method :policy
10
+ end
11
+ end
12
+
13
+ def authorize(controller: nil, query: nil, record: nil)
14
+ @_authorization_performed = true
15
+ controller ||= controller_path
16
+ query ||= "#{action_name}?"
17
+
18
+ policy(controller, record).public_send(query) ||
19
+ raise(NotAuthorizedError, self.class)
20
+ end
21
+
22
+ def policy(controller, record)
23
+ PolicyFinder.find(controller).new(record)
24
+ end
25
+
26
+ def verify_authorization_performed
27
+ authorization_performed? ||
28
+ raise(AuthorizationNotPerformedError, self.class)
29
+ end
30
+
31
+ private
32
+
33
+ def authorization_performed?
34
+ !!@_authorization_performed
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Guarda
4
+ class PolicyFinder
5
+ def initialize(controller_name)
6
+ @controller_name = controller_name
7
+ end
8
+
9
+ def self.find(controller_name)
10
+ new(controller_name).find
11
+ end
12
+
13
+ def find
14
+ policy_class.presence || raise(NotFoundError, policy_class_name)
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :controller_name
20
+
21
+ def policy_class
22
+ policy_class_name.safe_constantize
23
+ end
24
+
25
+ def policy_class_name
26
+ controller_name.camelize.concat("Policy")
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Guarda
4
+ VERSION = "0.1.0"
5
+ end
data/lib/guarda.rb CHANGED
@@ -1,5 +1,13 @@
1
- class Guarda
2
- def self.hi
3
- puts "Hello World"
4
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+ require_relative "guarda/version"
5
+ require_relative "guarda/policy_finder"
6
+ require_relative "guarda/authorization"
7
+
8
+ module Guarda
9
+ class Error < StandardError; end
10
+ class Authorization::NotAuthorizedError < Error; end
11
+ class Authorization::AuthorizationNotPerformedError < Error; end
12
+ class PolicyFinder::NotFoundError < Error; end
5
13
  end
data/sig/guarda.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Guarda
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata CHANGED
@@ -1,26 +1,65 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guarda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdullah Hashim
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-21 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Another Authorization Gem
14
- email: abdul@hey.com
11
+ date: 2024-01-28 00:00:00.000000000 Z
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: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest-reporters
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - abdul@hey.com
15
44
  executables: []
16
45
  extensions: []
17
46
  extra_rdoc_files: []
18
47
  files:
48
+ - LICENSE.txt
49
+ - README.md
50
+ - Rakefile
51
+ - guarda.gemspec
19
52
  - lib/guarda.rb
20
- homepage: https://rubygems.org/gems/guarda
53
+ - lib/guarda/authorization.rb
54
+ - lib/guarda/policy_finder.rb
55
+ - lib/guarda/version.rb
56
+ - sig/guarda.rbs
57
+ homepage: https://wwww.guidedrails.com
21
58
  licenses:
22
59
  - MIT
23
- metadata: {}
60
+ metadata:
61
+ homepage_uri: https://wwww.guidedrails.com
62
+ source_code_uri: https://github.com/Guided-Rails/guarda
24
63
  post_install_message:
25
64
  rdoc_options: []
26
65
  require_paths:
@@ -29,7 +68,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
29
68
  requirements:
30
69
  - - ">="
31
70
  - !ruby/object:Gem::Version
32
- version: '0'
71
+ version: 2.6.0
33
72
  required_rubygems_version: !ruby/object:Gem::Requirement
34
73
  requirements:
35
74
  - - ">="
@@ -39,5 +78,5 @@ requirements: []
39
78
  rubygems_version: 3.3.7
40
79
  signing_key:
41
80
  specification_version: 4
42
- summary: Authorization
81
+ summary: Another authorization gem
43
82
  test_files: []