RubyRoles 0.1.0

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
+ SHA256:
3
+ metadata.gz: f2f0abb404befe21a94ffa66c559eca74a88800e51ed1ae6addf2ab8c541780c
4
+ data.tar.gz: b12d327d34fe9cecd55f3d93d05014a808a7c8f0342a311e2dfa28b8977c7c5a
5
+ SHA512:
6
+ metadata.gz: b00b2af9d5e7a3b7251b5cb586546e9e54a75e7130c73f59fa44941104ee3310f8536cc882d54ed2bfb5124822955781c3492e670d76a05457ea68e35601d148
7
+ data.tar.gz: 4d480a2b5a08c3c5f9ac37c612092222f425bb64319cf8fe7c557627dee0a8ea650990a5b20624961071546d145ebdd8b8d6c57ea3ebe854dca642aa5f8716fc
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
@@ -0,0 +1,40 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ </content>
12
+ <orderEntry type="inheritedJdk" />
13
+ <orderEntry type="sourceFolder" forTests="false" />
14
+ <orderEntry type="library" scope="PROVIDED" name="activesupport (v8.0.2, ruby-3.2.2-p53) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="base64 (v0.3.0, ruby-3.2.2-p53) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="benchmark (v0.4.1, ruby-3.2.2-p53) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="bigdecimal (v3.2.2, ruby-3.2.2-p53) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.7.1, ruby-3.2.2-p53) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.3.5, ruby-3.2.2-p53) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="connection_pool (v2.5.3, ruby-3.2.2-p53) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="date (v3.4.1, ruby-3.2.2-p53) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="drb (v2.2.3, ruby-3.2.2-p53) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="erb (v5.0.2, ruby-3.2.2-p53) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="i18n (v1.14.7, ruby-3.2.2-p53) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="io-console (v0.8.1, ruby-3.2.2-p53) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="irb (v1.15.2, ruby-3.2.2-p53) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="logger (v1.7.0, ruby-3.2.2-p53) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="minitest (v5.25.5, ruby-3.2.2-p53) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="pp (v0.6.2, ruby-3.2.2-p53) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="prettyprint (v0.2.0, ruby-3.2.2-p53) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="psych (v5.2.6, ruby-3.2.2-p53) [gem]" level="application" />
32
+ <orderEntry type="library" scope="PROVIDED" name="rake (v13.3.0, ruby-3.2.2-p53) [gem]" level="application" />
33
+ <orderEntry type="library" scope="PROVIDED" name="rdoc (v6.14.2, ruby-3.2.2-p53) [gem]" level="application" />
34
+ <orderEntry type="library" scope="PROVIDED" name="reline (v0.6.2, ruby-3.2.2-p53) [gem]" level="application" />
35
+ <orderEntry type="library" scope="PROVIDED" name="securerandom (v0.4.1, ruby-3.2.2-p53) [gem]" level="application" />
36
+ <orderEntry type="library" scope="PROVIDED" name="stringio (v3.1.7, ruby-3.2.2-p53) [gem]" level="application" />
37
+ <orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.6, ruby-3.2.2-p53) [gem]" level="application" />
38
+ <orderEntry type="library" scope="PROVIDED" name="uri (v1.0.3, ruby-3.2.2-p53) [gem]" level="application" />
39
+ </component>
40
+ </module>
data/.idea/aws.xml ADDED
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="accountSettings">
4
+ <option name="activeRegion" value="us-east-1" />
5
+ <option name="recentlyUsedRegions">
6
+ <list>
7
+ <option value="us-east-1" />
8
+ </list>
9
+ </option>
10
+ </component>
11
+ </project>
@@ -0,0 +1,17 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
5
+ <option name="ignoredPackages">
6
+ <value>
7
+ <list size="4">
8
+ <item index="0" class="java.lang.String" itemvalue="pulumi_awsx" />
9
+ <item index="1" class="java.lang.String" itemvalue="pulumi_nuage" />
10
+ <item index="2" class="java.lang.String" itemvalue="pulumi-aws" />
11
+ <item index="3" class="java.lang.String" itemvalue="pulumi" />
12
+ </list>
13
+ </value>
14
+ </option>
15
+ </inspection_tool>
16
+ </profile>
17
+ </component>
data/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="ruby-3.2.2-p53" project-jdk-type="RUBY_SDK" />
4
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/RubyRoles.iml" filepath="$PROJECT_DIR$/.idea/RubyRoles.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # RubyRoles
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/RubyRoles`. 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
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/RubyRoles.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/lib/RubyRoles.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ruby_roles/version"
4
+ require_relative "ruby_roles/concerns/roles_mgmt"
5
+
6
+ module RubyRoles
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ end
@@ -0,0 +1,129 @@
1
+ module RubyRoles
2
+ module Concerns
3
+ module RolesMgmt
4
+ extend ActiveSupport::Concern
5
+
6
+
7
+ included do
8
+ @role_list = []
9
+
10
+ #
11
+ #
12
+ # Class Methods
13
+ #
14
+ #
15
+
16
+ # Sets the acceptable list of Roles
17
+ def self.roles(*roles_list)
18
+ @role_list = canonical_syms *roles_list
19
+ @role_list.each do |method|
20
+ define_method "is_#{method}?" do
21
+ self.has_role? method
22
+ end
23
+ end
24
+ end
25
+
26
+ # Returns the list of acceptable roles
27
+ def self.valid_roles
28
+ @role_list
29
+ end
30
+
31
+ # Returns the bit mask for a given set of roles
32
+ def self.mask_for(*roles_list)
33
+ roles_syms_to_bits(*roles_list)
34
+ end
35
+
36
+ # Roles Display Management
37
+ # Returns [["Role xxx",1],["Role xxx",2],["Role xxx",4]]
38
+ def self.roles_array(*hidden_roles)
39
+ hidden = canonical_syms(hidden_roles)||[]
40
+ @roles_array_cache ||= {}
41
+ @roles_array_cache[hidden.to_s] ||=
42
+ @role_list.reject do |role|
43
+ hidden.include? role
44
+ end.map do |role|
45
+ [ self.role_human_readable(role), self.roles_syms_to_bits(role) ]
46
+ end.compact
47
+ end
48
+
49
+ # Return human readable string from role
50
+ def self.role_human_readable(role)
51
+ I18n.t("roles.names.#{role}")
52
+ end
53
+ # Return list of human readable strings matching the roles
54
+ def roles_human_readable
55
+ self.class.roles_bits_to_syms(self.roles_mask).map { |role|self.class.role_human_readable role }
56
+ end
57
+
58
+
59
+ #
60
+ #
61
+ # Private Methods
62
+ #
63
+ #
64
+ private
65
+
66
+ # Support: Turn a list/array of values into a simple flat array of symbols
67
+ def self.canonical_syms(*syms)
68
+ return nil if syms.nil?
69
+ [ *syms ].flatten.map { |sym|sym.to_sym }
70
+ end
71
+
72
+ # Support: Turn a list of symbols into a bitmask
73
+ def self.roles_syms_to_bits(*syms)
74
+ (canonical_syms(*syms) & @role_list).map { |r| 2**@role_list.index(r) }.inject(0, :+)
75
+ end
76
+
77
+ # Support: Turn a bits mask into a list of symbols
78
+ def self.roles_bits_to_syms(bits)
79
+ @role_list.reject do |r|
80
+ ((bits.to_i||0)&2**@role_list.index(r)).zero?
81
+ end
82
+ end
83
+ end
84
+
85
+
86
+ #
87
+ #
88
+ # Instance Methods
89
+ #
90
+ #
91
+
92
+ # Set the valid set of roles for a given user
93
+ def roles=(*roles)
94
+ self.roles_mask = self.class.roles_syms_to_bits(*roles)
95
+ self.roles
96
+ end
97
+
98
+ # Return the list of roles this user has
99
+ def roles
100
+ self.class.roles_bits_to_syms(roles_mask)
101
+ end
102
+
103
+ # Returns TRUE if user has this specific role
104
+ def has_role?(role)
105
+ (self.roles_mask & self.class.roles_syms_to_bits(role)) !=0
106
+ end
107
+
108
+ # Returns TRUE if user has any of the specified roles
109
+ def has_any_roles?(*roles)
110
+ (self.roles_mask & self.class.roles_syms_to_bits(*roles)) !=0
111
+ end
112
+
113
+ # Returns TRUE if user has all the specified roles
114
+ def has_all_roles?(*roles)
115
+ bits = self.class.roles_syms_to_bits(*roles)
116
+ (self.roles_mask & bits) == bits
117
+ end
118
+
119
+ def add_roles(*roles)
120
+ self.roles_mask = (self.roles_mask||0) | self.class.roles_syms_to_bits(*roles)
121
+ self.roles
122
+ end
123
+ def delete_roles(*roles)
124
+ self.roles_mask = (self.roles_mask||0) & ~self.class.roles_syms_to_bits(*roles)
125
+ self.roles
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyRoles
4
+ VERSION = "0.1.0"
5
+ end
data/sig/RubyRoles.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module RubyRoles
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: RubyRoles
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lee Atchison
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-07-25 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: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ description: Assign roles to users, accounts, user_accounts, and other models in a
28
+ Ruby on Rails application.
29
+ email:
30
+ - lee@leeatchison.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".idea/.gitignore"
36
+ - ".idea/RubyRoles.iml"
37
+ - ".idea/aws.xml"
38
+ - ".idea/inspectionProfiles/Project_Default.xml"
39
+ - ".idea/misc.xml"
40
+ - ".idea/modules.xml"
41
+ - ".idea/vcs.xml"
42
+ - README.md
43
+ - Rakefile
44
+ - lib/RubyRoles.rb
45
+ - lib/ruby_roles/concerns/roles_mgmt.rb
46
+ - lib/ruby_roles/version.rb
47
+ - sig/RubyRoles.rbs
48
+ homepage: https://github.com/leeatchison/RubyRoles
49
+ licenses: []
50
+ metadata:
51
+ allowed_push_host: https://rubygems.org
52
+ homepage_uri: https://github.com/leeatchison/RubyRoles
53
+ source_code_uri: https://github.com/leeatchison/RubyRoles
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.2.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.4.10
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Assign roles to users, accounts, and user_accounts.
73
+ test_files: []