mini-lite-tool 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.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/cancancan-3.6.1/cancancan.gemspec +29 -0
  3. data/cancancan-3.6.1/init.rb +3 -0
  4. data/cancancan-3.6.1/lib/cancan/ability/actions.rb +93 -0
  5. data/cancancan-3.6.1/lib/cancan/ability/rules.rb +96 -0
  6. data/cancancan-3.6.1/lib/cancan/ability/strong_parameter_support.rb +41 -0
  7. data/cancancan-3.6.1/lib/cancan/ability.rb +312 -0
  8. data/cancancan-3.6.1/lib/cancan/class_matcher.rb +30 -0
  9. data/cancancan-3.6.1/lib/cancan/conditions_matcher.rb +147 -0
  10. data/cancancan-3.6.1/lib/cancan/config.rb +101 -0
  11. data/cancancan-3.6.1/lib/cancan/controller_additions.rb +399 -0
  12. data/cancancan-3.6.1/lib/cancan/controller_resource.rb +141 -0
  13. data/cancancan-3.6.1/lib/cancan/controller_resource_builder.rb +26 -0
  14. data/cancancan-3.6.1/lib/cancan/controller_resource_finder.rb +42 -0
  15. data/cancancan-3.6.1/lib/cancan/controller_resource_loader.rb +120 -0
  16. data/cancancan-3.6.1/lib/cancan/controller_resource_name_finder.rb +23 -0
  17. data/cancancan-3.6.1/lib/cancan/controller_resource_sanitizer.rb +32 -0
  18. data/cancancan-3.6.1/lib/cancan/exceptions.rb +70 -0
  19. data/cancancan-3.6.1/lib/cancan/matchers.rb +56 -0
  20. data/cancancan-3.6.1/lib/cancan/model_adapters/abstract_adapter.rb +77 -0
  21. data/cancancan-3.6.1/lib/cancan/model_adapters/active_record_4_adapter.rb +62 -0
  22. data/cancancan-3.6.1/lib/cancan/model_adapters/active_record_5_adapter.rb +61 -0
  23. data/cancancan-3.6.1/lib/cancan/model_adapters/active_record_adapter.rb +229 -0
  24. data/cancancan-3.6.1/lib/cancan/model_adapters/conditions_extractor.rb +75 -0
  25. data/cancancan-3.6.1/lib/cancan/model_adapters/conditions_normalizer.rb +49 -0
  26. data/cancancan-3.6.1/lib/cancan/model_adapters/default_adapter.rb +9 -0
  27. data/cancancan-3.6.1/lib/cancan/model_adapters/sti_normalizer.rb +47 -0
  28. data/cancancan-3.6.1/lib/cancan/model_adapters/strategies/base.rb +40 -0
  29. data/cancancan-3.6.1/lib/cancan/model_adapters/strategies/joined_alias_each_rule_as_exists_subquery.rb +93 -0
  30. data/cancancan-3.6.1/lib/cancan/model_adapters/strategies/joined_alias_exists_subquery.rb +31 -0
  31. data/cancancan-3.6.1/lib/cancan/model_adapters/strategies/left_join.rb +11 -0
  32. data/cancancan-3.6.1/lib/cancan/model_adapters/strategies/subquery.rb +18 -0
  33. data/cancancan-3.6.1/lib/cancan/model_additions.rb +34 -0
  34. data/cancancan-3.6.1/lib/cancan/parameter_validators.rb +9 -0
  35. data/cancancan-3.6.1/lib/cancan/relevant.rb +29 -0
  36. data/cancancan-3.6.1/lib/cancan/rule.rb +140 -0
  37. data/cancancan-3.6.1/lib/cancan/rules_compressor.rb +41 -0
  38. data/cancancan-3.6.1/lib/cancan/sti_detector.rb +12 -0
  39. data/cancancan-3.6.1/lib/cancan/unauthorized_message_resolver.rb +24 -0
  40. data/cancancan-3.6.1/lib/cancan/version.rb +5 -0
  41. data/cancancan-3.6.1/lib/cancan.rb +29 -0
  42. data/cancancan-3.6.1/lib/cancancan.rb +6 -0
  43. data/cancancan-3.6.1/lib/generators/cancan/ability/USAGE +4 -0
  44. data/cancancan-3.6.1/lib/generators/cancan/ability/ability_generator.rb +13 -0
  45. data/cancancan-3.6.1/lib/generators/cancan/ability/templates/ability.rb +32 -0
  46. data/mini-lite-tool.gemspec +11 -0
  47. metadata +85 -0
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CanCan
4
+ # This module adds the accessible_by class method to a model. It is included in the model adapters.
5
+ module ModelAdditions
6
+ module ClassMethods
7
+ # Returns a scope which fetches only the records that the passed ability
8
+ # can perform a given action on. The action defaults to :index. This
9
+ # is usually called from a controller and passed the +current_ability+.
10
+ #
11
+ # @articles = Article.accessible_by(current_ability)
12
+ #
13
+ # Here only the articles which the user is able to read will be returned.
14
+ # If the user does not have permission to read any articles then an empty
15
+ # result is returned. Since this is a scope it can be combined with any
16
+ # other scopes or pagination.
17
+ #
18
+ # An alternative action can optionally be passed as a second argument.
19
+ #
20
+ # @articles = Article.accessible_by(current_ability, :update)
21
+ #
22
+ # Here only the articles which the user can update are returned.
23
+ def accessible_by(ability, action = :index, strategy: CanCan.accessible_by_strategy)
24
+ CanCan.with_accessible_by_strategy(strategy) do
25
+ ability.model_adapter(self, action).database_records
26
+ end
27
+ end
28
+ end
29
+
30
+ def self.included(base)
31
+ base.extend ClassMethods
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CanCan
4
+ module ParameterValidators
5
+ def valid_attribute_param?(attribute)
6
+ attribute.nil? || attribute.is_a?(Symbol) || (attribute.is_a?(Array) && attribute.all? { |a| a.is_a?(Symbol) })
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CanCan
4
+ module Relevant
5
+ # Matches both the action, subject, and attribute, not necessarily the conditions
6
+ def relevant?(action, subject)
7
+ subject = subject.values.first if subject.class == Hash
8
+ @match_all || (matches_action?(action) && matches_subject?(subject))
9
+ end
10
+
11
+ private
12
+
13
+ def matches_action?(action)
14
+ @expanded_actions.include?(:manage) || @expanded_actions.include?(action)
15
+ end
16
+
17
+ def matches_subject?(subject)
18
+ @subjects.include?(:all) || @subjects.include?(subject) || matches_subject_class?(subject)
19
+ end
20
+
21
+ def matches_subject_class?(subject)
22
+ @subjects.any? do |sub|
23
+ sub.is_a?(Module) && (subject.is_a?(sub) ||
24
+ subject.class.to_s == sub.to_s ||
25
+ (subject.is_a?(Module) && subject.ancestors.include?(sub)))
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,140 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'conditions_matcher.rb'
4
+ require_relative 'class_matcher.rb'
5
+ require_relative 'relevant.rb'
6
+
7
+ module CanCan
8
+ # This class is used internally and should only be called through Ability.
9
+ # it holds the information about a "can" call made on Ability and provides
10
+ # helpful methods to determine permission checking and conditions hash generation.
11
+ class Rule # :nodoc:
12
+ include ConditionsMatcher
13
+ include Relevant
14
+ include ParameterValidators
15
+ attr_reader :base_behavior, :subjects, :actions, :conditions, :attributes, :block
16
+ attr_writer :expanded_actions, :conditions
17
+
18
+ # The first argument when initializing is the base_behavior which is a true/false
19
+ # value. True for "can" and false for "cannot". The next two arguments are the action
20
+ # and subject respectively (such as :read, @project). The third argument is a hash
21
+ # of conditions and the last one is the block passed to the "can" call.
22
+ def initialize(base_behavior, action, subject, *extra_args, &block)
23
+ # for backwards compatibility, attributes are an optional parameter. Check if
24
+ # attributes were passed or are actually conditions
25
+ attributes, extra_args = parse_attributes_from_extra_args(extra_args)
26
+ condition_and_block_check(extra_args, block, action, subject)
27
+ @match_all = action.nil? && subject.nil?
28
+ raise Error, "Subject is required for #{action}" if action && subject.nil?
29
+
30
+ @base_behavior = base_behavior
31
+ @actions = wrap(action)
32
+ @subjects = wrap(subject)
33
+ @attributes = wrap(attributes)
34
+ @conditions = extra_args || {}
35
+ @block = block
36
+ end
37
+
38
+ def inspect
39
+ repr = "#<#{self.class.name}"
40
+ repr += "#{@base_behavior ? 'can' : 'cannot'} #{@actions.inspect}, #{@subjects.inspect}, #{@attributes.inspect}"
41
+
42
+ if with_scope?
43
+ repr += ", #{@conditions.where_values_hash}"
44
+ elsif [Hash, String].include?(@conditions.class)
45
+ repr += ", #{@conditions.inspect}"
46
+ end
47
+
48
+ repr + '>'
49
+ end
50
+
51
+ def can_rule?
52
+ base_behavior
53
+ end
54
+
55
+ def cannot_catch_all?
56
+ !can_rule? && catch_all?
57
+ end
58
+
59
+ def catch_all?
60
+ (with_scope? && @conditions.where_values_hash.empty?) ||
61
+ (!with_scope? && [nil, false, [], {}, '', ' '].include?(@conditions))
62
+ end
63
+
64
+ def only_block?
65
+ conditions_empty? && @block
66
+ end
67
+
68
+ def only_raw_sql?
69
+ @block.nil? && !conditions_empty? && !@conditions.is_a?(Hash)
70
+ end
71
+
72
+ def with_scope?
73
+ defined?(ActiveRecord) && @conditions.is_a?(ActiveRecord::Relation)
74
+ end
75
+
76
+ def associations_hash(conditions = @conditions)
77
+ hash = {}
78
+ if conditions.is_a? Hash
79
+ conditions.map do |name, value|
80
+ hash[name] = associations_hash(value) if value.is_a? Hash
81
+ end
82
+ end
83
+ hash
84
+ end
85
+
86
+ def attributes_from_conditions
87
+ attributes = {}
88
+ if @conditions.is_a? Hash
89
+ @conditions.each do |key, value|
90
+ attributes[key] = value unless [Array, Range, Hash].include? value.class
91
+ end
92
+ end
93
+ attributes
94
+ end
95
+
96
+ def matches_attributes?(attribute)
97
+ return true if @attributes.empty?
98
+ return @base_behavior if attribute.nil?
99
+
100
+ @attributes.include?(attribute.to_sym)
101
+ end
102
+
103
+ private
104
+
105
+ def matches_action?(action)
106
+ @expanded_actions.include?(:manage) || @expanded_actions.include?(action)
107
+ end
108
+
109
+ def matches_subject?(subject)
110
+ @subjects.include?(:all) || @subjects.include?(subject) || matches_subject_class?(subject)
111
+ end
112
+
113
+ def matches_subject_class?(subject)
114
+ SubjectClassMatcher.matches_subject_class?(@subjects, subject)
115
+ end
116
+
117
+ def parse_attributes_from_extra_args(args)
118
+ attributes = args.shift if valid_attribute_param?(args.first)
119
+ extra_args = args.shift
120
+ [attributes, extra_args]
121
+ end
122
+
123
+ def condition_and_block_check(conditions, block, action, subject)
124
+ return unless conditions.is_a?(Hash) && block
125
+
126
+ raise BlockAndConditionsError, 'A hash of conditions is mutually exclusive with a block. ' \
127
+ "Check \":#{action} #{subject}\" ability."
128
+ end
129
+
130
+ def wrap(object)
131
+ if object.nil?
132
+ []
133
+ elsif object.respond_to?(:to_ary)
134
+ object.to_ary || [object]
135
+ else
136
+ [object]
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'conditions_matcher.rb'
4
+ module CanCan
5
+ class RulesCompressor
6
+ attr_reader :initial_rules, :rules_collapsed
7
+
8
+ def initialize(rules)
9
+ @initial_rules = rules
10
+ @rules_collapsed = compress(@initial_rules)
11
+ end
12
+
13
+ def compress(array)
14
+ array = simplify(array)
15
+ idx = array.rindex(&:catch_all?)
16
+ return array unless idx
17
+
18
+ value = array[idx]
19
+ array[idx..-1]
20
+ .drop_while { |n| n.base_behavior == value.base_behavior }
21
+ .tap { |a| a.unshift(value) unless value.cannot_catch_all? }
22
+ end
23
+
24
+ # If we have A OR (!A AND anything ), then we can simplify to A OR anything
25
+ # If we have A OR (A OR anything ), then we can simplify to A OR anything
26
+ # If we have !A AND (A OR something), then we can simplify it to !A AND something
27
+ # If we have !A AND (!A AND something), then we can simplify it to !A AND something
28
+ #
29
+ # So as soon as we see a condition that is the same as the previous one,
30
+ # we can skip it, no matter of the base_behavior
31
+ def simplify(rules)
32
+ seen = Set.new
33
+ rules.reverse_each.filter_map do |rule|
34
+ next if seen.include?(rule.conditions)
35
+
36
+ seen.add(rule.conditions)
37
+ rule
38
+ end.reverse
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ class StiDetector
4
+ def self.sti_class?(subject)
5
+ return false unless defined?(ActiveRecord::Base)
6
+ return false unless subject.respond_to?(:descends_from_active_record?)
7
+ return false if subject == :all || subject.descends_from_active_record?
8
+ return false unless subject < ActiveRecord::Base
9
+
10
+ true
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CanCan
4
+ module UnauthorizedMessageResolver
5
+ def unauthorized_message(action, subject)
6
+ subject = subject.values.last if subject.is_a?(Hash)
7
+ keys = unauthorized_message_keys(action, subject)
8
+ variables = {}
9
+ variables[:action] = I18n.translate("actions.#{action}", default: action.to_s)
10
+ variables[:subject] = translate_subject(subject)
11
+ message = I18n.translate(keys.shift, **variables.merge(scope: :unauthorized, default: keys + ['']))
12
+ message.blank? ? nil : message
13
+ end
14
+
15
+ def translate_subject(subject)
16
+ klass = (subject.class == Class ? subject : subject.class)
17
+ if klass.respond_to?(:model_name)
18
+ klass.model_name.human
19
+ else
20
+ klass.to_s.underscore.humanize.downcase
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CanCan
4
+ VERSION = '3.6.1'.freeze
5
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cancan/version'
4
+ require 'cancan/config'
5
+ require 'cancan/parameter_validators'
6
+ require 'cancan/ability'
7
+ require 'cancan/rule'
8
+ require 'cancan/controller_resource'
9
+ require 'cancan/controller_additions'
10
+ require 'cancan/model_additions'
11
+ require 'cancan/exceptions'
12
+
13
+ require 'cancan/model_adapters/abstract_adapter'
14
+ require 'cancan/model_adapters/default_adapter'
15
+ require 'cancan/rules_compressor'
16
+
17
+ if defined? ActiveRecord
18
+ require 'cancan/model_adapters/conditions_extractor'
19
+ require 'cancan/model_adapters/conditions_normalizer'
20
+ require 'cancan/model_adapters/sti_normalizer'
21
+ require 'cancan/model_adapters/active_record_adapter'
22
+ require 'cancan/model_adapters/active_record_4_adapter'
23
+ require 'cancan/model_adapters/active_record_5_adapter'
24
+ require 'cancan/model_adapters/strategies/base'
25
+ require 'cancan/model_adapters/strategies/joined_alias_each_rule_as_exists_subquery'
26
+ require 'cancan/model_adapters/strategies/joined_alias_exists_subquery'
27
+ require 'cancan/model_adapters/strategies/left_join'
28
+ require 'cancan/model_adapters/strategies/subquery'
29
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cancan'
4
+
5
+ module CanCanCan
6
+ end
@@ -0,0 +1,4 @@
1
+ Description:
2
+ The cancan:ability generator creates an Ability class in the models
3
+ directory. You can move this file anywhere you want as long as it
4
+ is in the load path.
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cancan
4
+ module Generators
5
+ class AbilityGenerator < Rails::Generators::Base
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ def generate_ability
9
+ copy_file 'ability.rb', 'app/models/ability.rb'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Ability
4
+ include CanCan::Ability
5
+
6
+ def initialize(user)
7
+ # Define abilities for the user here. For example:
8
+ #
9
+ # return unless user.present?
10
+ # can :read, :all
11
+ # return unless user.admin?
12
+ # can :manage, :all
13
+ #
14
+ # The first argument to `can` is the action you are giving the user
15
+ # permission to do.
16
+ # If you pass :manage it will apply to every action. Other common actions
17
+ # here are :read, :create, :update and :destroy.
18
+ #
19
+ # The second argument is the resource the user can perform the action on.
20
+ # If you pass :all it will apply to every resource. Otherwise pass a Ruby
21
+ # class of the resource.
22
+ #
23
+ # The third argument is an optional hash of conditions to further filter the
24
+ # objects.
25
+ # For example, here the user can only update published articles.
26
+ #
27
+ # can :update, Article, published: true
28
+ #
29
+ # See the wiki for details:
30
+ # https://github.com/CanCanCommunity/cancancan/blob/develop/docs/define_check_abilities.md
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "mini-lite-tool"
3
+ s.version = "0.0.1"
4
+ s.summary = "Research test"
5
+ s.description = "University research based on cancancan"
6
+ s.authors = ["Andrey78"]
7
+ s.email = ["cakoc614@gmail.com"]
8
+ s.files = Dir.glob("**/*").reject { |f| f.end_with?('.gem') }
9
+ s.homepage = "https://rubygems.org/profiles/Andrey78"
10
+ s.license = "MIT"
11
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mini-lite-tool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrey78
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2026-07-06 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: University research based on cancancan
13
+ email:
14
+ - cakoc614@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - cancancan-3.6.1/cancancan.gemspec
20
+ - cancancan-3.6.1/init.rb
21
+ - cancancan-3.6.1/lib/cancan.rb
22
+ - cancancan-3.6.1/lib/cancan/ability.rb
23
+ - cancancan-3.6.1/lib/cancan/ability/actions.rb
24
+ - cancancan-3.6.1/lib/cancan/ability/rules.rb
25
+ - cancancan-3.6.1/lib/cancan/ability/strong_parameter_support.rb
26
+ - cancancan-3.6.1/lib/cancan/class_matcher.rb
27
+ - cancancan-3.6.1/lib/cancan/conditions_matcher.rb
28
+ - cancancan-3.6.1/lib/cancan/config.rb
29
+ - cancancan-3.6.1/lib/cancan/controller_additions.rb
30
+ - cancancan-3.6.1/lib/cancan/controller_resource.rb
31
+ - cancancan-3.6.1/lib/cancan/controller_resource_builder.rb
32
+ - cancancan-3.6.1/lib/cancan/controller_resource_finder.rb
33
+ - cancancan-3.6.1/lib/cancan/controller_resource_loader.rb
34
+ - cancancan-3.6.1/lib/cancan/controller_resource_name_finder.rb
35
+ - cancancan-3.6.1/lib/cancan/controller_resource_sanitizer.rb
36
+ - cancancan-3.6.1/lib/cancan/exceptions.rb
37
+ - cancancan-3.6.1/lib/cancan/matchers.rb
38
+ - cancancan-3.6.1/lib/cancan/model_adapters/abstract_adapter.rb
39
+ - cancancan-3.6.1/lib/cancan/model_adapters/active_record_4_adapter.rb
40
+ - cancancan-3.6.1/lib/cancan/model_adapters/active_record_5_adapter.rb
41
+ - cancancan-3.6.1/lib/cancan/model_adapters/active_record_adapter.rb
42
+ - cancancan-3.6.1/lib/cancan/model_adapters/conditions_extractor.rb
43
+ - cancancan-3.6.1/lib/cancan/model_adapters/conditions_normalizer.rb
44
+ - cancancan-3.6.1/lib/cancan/model_adapters/default_adapter.rb
45
+ - cancancan-3.6.1/lib/cancan/model_adapters/sti_normalizer.rb
46
+ - cancancan-3.6.1/lib/cancan/model_adapters/strategies/base.rb
47
+ - cancancan-3.6.1/lib/cancan/model_adapters/strategies/joined_alias_each_rule_as_exists_subquery.rb
48
+ - cancancan-3.6.1/lib/cancan/model_adapters/strategies/joined_alias_exists_subquery.rb
49
+ - cancancan-3.6.1/lib/cancan/model_adapters/strategies/left_join.rb
50
+ - cancancan-3.6.1/lib/cancan/model_adapters/strategies/subquery.rb
51
+ - cancancan-3.6.1/lib/cancan/model_additions.rb
52
+ - cancancan-3.6.1/lib/cancan/parameter_validators.rb
53
+ - cancancan-3.6.1/lib/cancan/relevant.rb
54
+ - cancancan-3.6.1/lib/cancan/rule.rb
55
+ - cancancan-3.6.1/lib/cancan/rules_compressor.rb
56
+ - cancancan-3.6.1/lib/cancan/sti_detector.rb
57
+ - cancancan-3.6.1/lib/cancan/unauthorized_message_resolver.rb
58
+ - cancancan-3.6.1/lib/cancan/version.rb
59
+ - cancancan-3.6.1/lib/cancancan.rb
60
+ - cancancan-3.6.1/lib/generators/cancan/ability/USAGE
61
+ - cancancan-3.6.1/lib/generators/cancan/ability/ability_generator.rb
62
+ - cancancan-3.6.1/lib/generators/cancan/ability/templates/ability.rb
63
+ - mini-lite-tool.gemspec
64
+ homepage: https://rubygems.org/profiles/Andrey78
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.6.2
83
+ specification_version: 4
84
+ summary: Research test
85
+ test_files: []