auxilium 3.0.24

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eb92dcedcc80162b42e9144c2337b19b0c78d568b9e13fc2e0a3b9a8e50ae4e2
4
+ data.tar.gz: c392c88f1c090d409a43821b19ad50f272dad09f0704616f8e05f0a0f2e81e70
5
+ SHA512:
6
+ metadata.gz: f060a273e1d6ab0e406931a8d7a57bfdb7cc773c2bfb95f150b66158386e745fef3f09a9f560e4b7461a0f9e4150dd5a8d90574b19517ac1b342658673cff896
7
+ data.tar.gz: 002030ab34ca8105b98dd653c6fbb3c2f1fe4a77abf82c2aac2366a14c88c87bdb1a3d352858fc1cd6a5845dfde5ac3fa80216bce28d9c73817f7197b2dc6f25
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in auxilium.gemspec
4
+ gemspec
5
+
6
+ gem 'responders', github: 'heartcombo/responders', branch: :main
7
+
8
+ gem 'solargraph', require: false
data/Gemfile.lock ADDED
@@ -0,0 +1,152 @@
1
+ GIT
2
+ remote: https://github.com/heartcombo/responders.git
3
+ revision: 161f205b649489d740821425560eecd355fa02be
4
+ branch: main
5
+ specs:
6
+ responders (3.0.1)
7
+ actionpack (>= 5.2)
8
+ railties (>= 5.2)
9
+
10
+ PATH
11
+ remote: .
12
+ specs:
13
+ auxilium (3.0.24)
14
+ actionpack (> 5.1)
15
+ activemodel (> 5.1)
16
+ activesupport (> 5.1)
17
+ pundit (> 2)
18
+ responders (> 3)
19
+ rolify (> 5)
20
+
21
+ GEM
22
+ remote: https://rubygems.org/
23
+ specs:
24
+ actionpack (7.0.3.1)
25
+ actionview (= 7.0.3.1)
26
+ activesupport (= 7.0.3.1)
27
+ rack (~> 2.0, >= 2.2.0)
28
+ rack-test (>= 0.6.3)
29
+ rails-dom-testing (~> 2.0)
30
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
31
+ actionview (7.0.3.1)
32
+ activesupport (= 7.0.3.1)
33
+ builder (~> 3.1)
34
+ erubi (~> 1.4)
35
+ rails-dom-testing (~> 2.0)
36
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
37
+ activemodel (7.0.3.1)
38
+ activesupport (= 7.0.3.1)
39
+ activesupport (7.0.3.1)
40
+ concurrent-ruby (~> 1.0, >= 1.0.2)
41
+ i18n (>= 1.6, < 2)
42
+ minitest (>= 5.1)
43
+ tzinfo (~> 2.0)
44
+ ast (2.4.2)
45
+ backport (1.2.0)
46
+ benchmark (0.2.0)
47
+ builder (3.2.4)
48
+ coderay (1.1.3)
49
+ concurrent-ruby (1.1.10)
50
+ crass (1.0.6)
51
+ diff-lcs (1.5.0)
52
+ e2mmap (0.1.0)
53
+ erubi (1.10.0)
54
+ i18n (1.12.0)
55
+ concurrent-ruby (~> 1.0)
56
+ jaro_winkler (1.5.4)
57
+ json (2.6.2)
58
+ kramdown (2.4.0)
59
+ rexml
60
+ kramdown-parser-gfm (1.1.0)
61
+ kramdown (~> 2.0)
62
+ loofah (2.18.0)
63
+ crass (~> 1.0.2)
64
+ nokogiri (>= 1.5.9)
65
+ method_source (1.0.0)
66
+ mini_portile2 (2.8.0)
67
+ minitest (5.16.2)
68
+ nokogiri (1.13.8)
69
+ mini_portile2 (~> 2.8.0)
70
+ racc (~> 1.4)
71
+ parallel (1.22.1)
72
+ parser (3.1.2.1)
73
+ ast (~> 2.4.1)
74
+ pry (0.14.1)
75
+ coderay (~> 1.1)
76
+ method_source (~> 1.0)
77
+ pundit (2.2.0)
78
+ activesupport (>= 3.0.0)
79
+ racc (1.6.0)
80
+ rack (2.2.4)
81
+ rack-test (2.0.2)
82
+ rack (>= 1.3)
83
+ rails-dom-testing (2.0.3)
84
+ activesupport (>= 4.2.0)
85
+ nokogiri (>= 1.6)
86
+ rails-html-sanitizer (1.4.3)
87
+ loofah (~> 2.3)
88
+ railties (7.0.3.1)
89
+ actionpack (= 7.0.3.1)
90
+ activesupport (= 7.0.3.1)
91
+ method_source
92
+ rake (>= 12.2)
93
+ thor (~> 1.0)
94
+ zeitwerk (~> 2.5)
95
+ rainbow (3.1.1)
96
+ rake (12.3.3)
97
+ regexp_parser (2.6.0)
98
+ reverse_markdown (2.1.1)
99
+ nokogiri
100
+ rexml (3.2.5)
101
+ rolify (6.0.0)
102
+ rubocop (1.37.1)
103
+ json (~> 2.3)
104
+ parallel (~> 1.10)
105
+ parser (>= 3.1.2.1)
106
+ rainbow (>= 2.2.2, < 4.0)
107
+ regexp_parser (>= 1.8, < 3.0)
108
+ rexml (>= 3.2.5, < 4.0)
109
+ rubocop-ast (>= 1.23.0, < 2.0)
110
+ ruby-progressbar (~> 1.7)
111
+ unicode-display_width (>= 1.4.0, < 3.0)
112
+ rubocop-ast (1.23.0)
113
+ parser (>= 3.1.1.0)
114
+ ruby-progressbar (1.11.0)
115
+ solargraph (0.47.2)
116
+ backport (~> 1.2)
117
+ benchmark
118
+ bundler (>= 1.17.2)
119
+ diff-lcs (~> 1.4)
120
+ e2mmap
121
+ jaro_winkler (~> 1.5)
122
+ kramdown (~> 2.3)
123
+ kramdown-parser-gfm (~> 1.1)
124
+ parser (~> 3.0)
125
+ reverse_markdown (>= 1.0.5, < 3)
126
+ rubocop (>= 0.52)
127
+ thor (~> 1.0)
128
+ tilt (~> 2.0)
129
+ yard (~> 0.9, >= 0.9.24)
130
+ thor (1.2.1)
131
+ tilt (2.0.11)
132
+ tzinfo (2.0.5)
133
+ concurrent-ruby (~> 1.0)
134
+ unicode-display_width (2.3.0)
135
+ webrick (1.7.0)
136
+ yard (0.9.28)
137
+ webrick (~> 1.7.0)
138
+ zeitwerk (2.6.0)
139
+
140
+ PLATFORMS
141
+ ruby
142
+
143
+ DEPENDENCIES
144
+ auxilium!
145
+ minitest (> 5.0)
146
+ pry
147
+ rake (~> 12.0)
148
+ responders!
149
+ solargraph
150
+
151
+ BUNDLED WITH
152
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Tom de Grunt
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Auxilium
2
+
3
+ Auxilium contains an assortment of utility classes that are too small to warrant their own gem.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'auxilium'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install auxilium
20
+
21
+ ## Usage
22
+
23
+ Use the source :)
24
+
25
+ ## Semver rake task
26
+
27
+ Auxilium contains a rake task that you can reuse in your projects to enable you to create releases using semantic versioning. To use this rake task in your own gems you need to do the following:
28
+
29
+ - Add auxilium to your gemspec (as atleast a development dependency) and to your Gemfile (specifying the right git source)
30
+ - Add the following snippet at the bottom of your Rakefile:
31
+
32
+ ```ruby
33
+ # Adds the Auxilium semver task
34
+ spec = Gem::Specification.find_by_name 'auxilium'
35
+ load "#{spec.gem_dir}/lib/tasks/semver.rake"
36
+ ```
37
+
38
+ After a bundle install you can see a new rake task named after your gem with the name gemname:semver
39
+
40
+ ## Development
41
+
42
+ 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.
43
+
44
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/auxilium.
49
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ import 'lib/tasks/semver.rake'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.libs << "lib"
8
+ t.test_files = FileList["test/**/*_test.rb"]
9
+ end
10
+
11
+ task :default => :test
data/auxilium.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ require_relative 'lib/auxilium/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'auxilium'
5
+ spec.version = Auxilium::VERSION
6
+ spec.authors = ['Andre Meij']
7
+ spec.email = ['andre@itsmeij.com']
8
+
9
+ spec.summary = 'Random utilities.'
10
+ spec.description = 'Utility classes that are to small to warrant a own gem for now.'
11
+ spec.homepage = 'https://code.entropydecelerator.com/components/auxilium'
12
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.5')
13
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = 'https://code.entropydecelerator.com/components/auxilium'
17
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_dependency 'actionpack', '> 5.1'
29
+ spec.add_dependency 'activemodel', '> 5.1'
30
+ spec.add_dependency 'activesupport', '> 5.1'
31
+ spec.add_dependency 'pundit', '> 2'
32
+ spec.add_dependency 'responders', '> 3'
33
+ spec.add_dependency 'rolify', '> 5'
34
+
35
+ spec.add_development_dependency 'minitest', '> 5.0'
36
+ spec.add_development_dependency 'pry'
37
+ spec.add_development_dependency 'rake', '~> 12.0'
38
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "auxilium"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auxilium
4
+ module Concerns
5
+ module AdminAuthenticated
6
+ extend ActiveSupport::Concern
7
+
8
+ def admin_authenticated
9
+ authenticate_user!
10
+
11
+ redirect_to root_path unless current_user.has_role?(:admin)
12
+ end
13
+
14
+ included do
15
+ before_action :admin_authenticated
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auxilium
4
+ module Concerns
5
+ module Authenticated
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ before_action :authenticate_user_from_token!
10
+ before_action :authenticate_user!
11
+ before_action :set_user, :log_request_details
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auxilium
4
+ module Concerns
5
+ module Metadata
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ validates :metadata_yaml, yaml: true
10
+ end
11
+
12
+ def metadata_yaml=(yaml)
13
+ write_attribute :metadata, YAML.safe_load(yaml.gsub("\t", ' '))
14
+ rescue StandardError
15
+ write_attribute :metadata, yaml
16
+ end
17
+
18
+ def metadata_yaml
19
+ return '' if attributes['metadata'].blank?
20
+
21
+ if attributes['metadata'].is_a? String
22
+ begin
23
+ YAML.load(attributes['metadata'])
24
+ rescue StandardError
25
+ attributes['metadata']
26
+ end
27
+ else
28
+ YAML.dump(attributes['metadata'])
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auxilium
4
+ module Concerns
5
+ module MetadataScoped
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ scope :metadata_blank, lambda { |name|
10
+ where('metadata->>:name IS NULL', name: name)
11
+ }
12
+
13
+ scope :metadata_eql, lambda { |name, value|
14
+ where('metadata->>:name = :value', name: name, value: value)
15
+ }
16
+
17
+ scope :metadata_blank_or_eql, lambda { |name, value|
18
+ where('metadata->>:name IS NULL OR metadata->>:name = :value', name: name, value: value)
19
+ }
20
+
21
+ scope :metadata_eql_or_blank_exclusive, lambda { |name, value|
22
+ result = where('metadata->>:name = :value', name: name, value: value)
23
+ result = where('metadata->>:name IS NULL', name: name) if result.none?
24
+ result
25
+ }
26
+
27
+ scope :metadata_in, lambda { |name, value|
28
+ where('metadata->>:name IN (:value)', name: name, value: value)
29
+ }
30
+
31
+ scope :metadata_blank_or_in, lambda { |name, value|
32
+ where('metadata->>:name IS NULL OR metadata->>:name IN (:value)', name: name, value: value)
33
+ }
34
+
35
+ scope :metadata_in_or_blank_exclusive, lambda { |name, value|
36
+ result = where('metadata->>:name IN (:value)', name: name, value: value)
37
+ result = where('metadata->>:name IS NULL', name: name) if result.none?
38
+ result
39
+ }
40
+
41
+ scope :metadata_contains, lambda { |name, value|
42
+ where('(metadata->>:name)::jsonb ? :value', name: name, value: value)
43
+ }
44
+
45
+ scope :contains, lambda { |name, value|
46
+ ActiveSupport::Deprecation.warn('Use metdata_contains instead')
47
+ metadata_contains(name, value)
48
+ }
49
+
50
+ scope :metadata_contains_or_blank, lambda { |name, value|
51
+ where('(metadata->>:name)::jsonb ? :value OR metadata->>:name IS NULL', name: name, value: value)
52
+ }
53
+
54
+ scope :contains_or_blank, lambda { |name, value|
55
+ ActiveSupport::Deprecation.warn('Use metdata_contains_or_blank instead')
56
+ metadata_contains_or_blank(name, value)
57
+ }
58
+
59
+ scope :metadata_contains_or_blank_exclusive, lambda { |name, value|
60
+ result = where('(metadata->>:name)::jsonb ? :value', name: name, value: value)
61
+ result = where('metadata->>:name IS NULL', name: name) if result.none?
62
+ result
63
+ }
64
+
65
+ scope :contains_or_blank_exclusive, lambda { |name, value|
66
+ ActiveSupport::Deprecation.warn('Use metdata_contains_or_blank_exclusive instead')
67
+ metadata_contains_or_blank_exclusive(name, value)
68
+ }
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auxilium
4
+ module Concerns
5
+ module ModelNameShortcuts
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ delegate :singular_model_name, :plural_model_name, to: :class
10
+ end
11
+
12
+ class_methods do
13
+ def singular_model_name
14
+ model_name.human(count: 1)
15
+ end
16
+
17
+ def plural_model_name
18
+ model_name.human(count: 2)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auxilium
4
+ module Concerns
5
+ end
6
+ end
@@ -0,0 +1,56 @@
1
+ module Auxilium
2
+ class EasyCrypt
3
+ # When no digest is given, the default Rails digest is used.
4
+ # Digest can be something like OpenSSL::Digest::SHA1 or OpenSSL::Digest::SHA256
5
+ def initialize(key_base, digest: OpenSSL::Digest::SHA1)
6
+ @key_base = key_base
7
+ @digest = digest
8
+ end
9
+
10
+ def encrypt(text)
11
+ text = text.to_s unless text.is_a?(String)
12
+
13
+ # Return the crypted text is it was already crypted by this routine
14
+ return text if crypted?(text)
15
+ return text if text.blank?
16
+
17
+ data = encrypted(text)
18
+ raise StandardError, 'WTF' unless decrypt(data)
19
+ data
20
+ end
21
+
22
+ def decrypt(data)
23
+ return data unless crypted?(data)
24
+
25
+ salt, data = data.gsub(/^EasyCrypt@/, '').split("$$", 2)
26
+
27
+ crypt(salt).decrypt_and_verify(data)
28
+ end
29
+
30
+ private
31
+
32
+ def encrypted(text)
33
+ salt = generate_salt
34
+ encrypted_data = crypt(salt).encrypt_and_sign(text)
35
+
36
+ "EasyCrypt@#{salt}$$#{encrypted_data}"
37
+ end
38
+
39
+ def crypt(salt)
40
+ key = ActiveSupport::KeyGenerator.new(@key_base, hash_digest_class: @digest).generate_key(salt, key_length)
41
+ ActiveSupport::MessageEncryptor.new(key, cipher: 'aes-256-gcm')
42
+ end
43
+
44
+ def key_length
45
+ @key_length ||= ActiveSupport::MessageEncryptor.key_len
46
+ end
47
+
48
+ def generate_salt
49
+ SecureRandom.hex(key_length)
50
+ end
51
+
52
+ def crypted?(text)
53
+ text =~ /^EasyCrypt@[0-9a-f]+\$\$[^-]+--[^-]+--[^-]+/
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,20 @@
1
+ module Auxilium
2
+ module Grape
3
+ class ParameterFilter
4
+ class << self
5
+ FILTER_REGEX = /password|token|api_key|Authorization/i
6
+
7
+ def filter(hash, regex = FILTER_REGEX)
8
+ hash = hash.dup
9
+ hash.each do |k, v|
10
+ hash[k] = '[FILTERED]' if k.to_s =~ FILTER_REGEX
11
+ hash[k] = filter(v, regex) if v.is_a?(Hash)
12
+ hash[k] = v.map { |v| v.is_a?(Hash) ? filter(v, regex) : v } if v.is_a?(Array)
13
+ end
14
+
15
+ hash
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Grape
4
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auxilium
4
+ class IntegerChunker
5
+ def initialize(number)
6
+ @number = number
7
+ end
8
+
9
+ def chunks_of(chunk_size, random: false)
10
+ number = @number
11
+ chunks = []
12
+
13
+ while number > 0
14
+ this_chunk_size = random ? rand(chunk_size - 1) + 1 : chunk_size
15
+ number -= this_chunk_size
16
+
17
+ if number < 0
18
+ this_chunk_size += number
19
+ number = 0
20
+ end
21
+
22
+ chunks << this_chunk_size
23
+ end
24
+
25
+ chunks
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ not_an_allowed_state: is not an allowed state
5
+ not_in_an_allowed_state: is not in an allowed state
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This responder modifies your current responder to redirect
4
+ # to the collection page on POST/PUT/DELETE if you use save, not for 'continue'.
5
+ module Auxilium
6
+ module ContinueResponder
7
+ protected
8
+
9
+ def navigation_location
10
+ return options[:location] if options[:location] && (controller.is_a?(Devise::SessionsController) || controller.is_a?(Devise::PasswordsController))
11
+ return options[:location] if controller.params[:commit] == 'continue' && options[:location]
12
+ return options[:collection_location].call if %w[save commit].include?(controller.params[:commit]) && options[:collection_location]
13
+ return resource_location if controller.params[:commit] == 'continue'
14
+
15
+ klass = resources.last.class
16
+
17
+ if klass.respond_to?(:model_name)
18
+ resources[0...-1] << klass.model_name.route_key.to_sym
19
+ else
20
+ resources
21
+ end
22
+ end
23
+
24
+ def navigation_behavior(error)
25
+ if get?
26
+ raise error
27
+ elsif has_errors? && options[:error_location]
28
+ redirect_to options[:error_location].call, status: :see_other
29
+ elsif has_errors? && default_action
30
+ render error_rendering_options
31
+ else
32
+ redirect_to navigation_location, status: :see_other
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,8 @@
1
+ module Auxilium
2
+ class Responder < ActionController::Responder
3
+ include Responders::HttpCacheResponder
4
+
5
+ include SignumResponder
6
+ include ContinueResponder
7
+ end
8
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_view'
4
+
5
+ module Auxilium
6
+ module SignumResponder
7
+ class << self
8
+ attr_accessor :signum_keys, :namespace_lookup, :helper
9
+ end
10
+
11
+ self.signum_keys = %i[success error]
12
+ self.namespace_lookup = false
13
+ self.helper = Object.new.extend(
14
+ ActionView::Helpers::TranslationHelper,
15
+ ActionView::Helpers::TagHelper
16
+ )
17
+
18
+ def initialize(controller, resources, options = {})
19
+ super
20
+ @signum = options.delete(:signum)
21
+ @success = options.delete(:success)
22
+ @error = options.delete(:error)
23
+ end
24
+
25
+ def to_html
26
+ send_signum! if send_signum?
27
+ super
28
+ end
29
+
30
+ def to_js
31
+ send_signum! if send_signum?
32
+ defined?(super) ? super : to_format
33
+ end
34
+
35
+ protected
36
+
37
+ def send_signum!
38
+ if has_errors?
39
+ status = SignumResponder.signum_keys.last
40
+ send_signum(status, @error)
41
+ else
42
+ status = SignumResponder.signum_keys.first
43
+ send_signum(status, @success)
44
+ end
45
+
46
+ return if sent_signum?
47
+
48
+ options = mount_i18n_options(status)
49
+ message = SignumResponder.helper.t options[:default].shift, **options
50
+ send_signum(status, message)
51
+ end
52
+
53
+ def send_signum(key, value)
54
+ return if value.blank?
55
+
56
+ @sent_signum = true
57
+ Signum.signal(controller.current_user, text: value, kind: key)
58
+ end
59
+
60
+ def send_signum? #:nodoc:
61
+ !get? && @signum != false
62
+ end
63
+
64
+ def sent_signum?
65
+ @sent_signum == true
66
+ end
67
+
68
+ def mount_i18n_options(status) #:nodoc:
69
+ options = {
70
+ default: signum_defaults_by_namespace(status),
71
+ resource_name: resource_name,
72
+ downcase_resource_name: resource_name.downcase
73
+ }
74
+
75
+ controller_options = controller_interpolation_options
76
+ options.merge!(controller_options) if controller_options
77
+
78
+ options
79
+ end
80
+
81
+ def controller_interpolation_options
82
+ controller.send(:signum_interpolation_options) if controller.respond_to?(:signum_interpolation_options, true)
83
+ end
84
+
85
+ def resource_name
86
+ if resource.class.respond_to?(:model_name)
87
+ resource.class.model_name.human
88
+ else
89
+ resource.class.name.underscore.humanize
90
+ end
91
+ end
92
+
93
+ def signum_defaults_by_namespace(status) #:nodoc:
94
+ defaults = []
95
+ slices = controller.controller_path.split('/')
96
+ lookup = SignumResponder.namespace_lookup
97
+
98
+ begin
99
+ controller_scope = :"signum.#{slices.fill(controller.controller_name, -1).join('.')}.#{controller.action_name}.#{status}"
100
+
101
+ actions_scope = lookup ? slices.fill('actions', -1).join('.') : :actions
102
+ actions_scope = :"signum.#{actions_scope}.#{controller.action_name}.#{status}"
103
+
104
+ defaults << :"#{controller_scope}_html"
105
+ defaults << controller_scope
106
+
107
+ defaults << :"#{actions_scope}_html"
108
+ defaults << actions_scope
109
+
110
+ slices.shift
111
+ end while slices.size > 0 && lookup
112
+
113
+ defaults << ''
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,18 @@
1
+ module Auxilium
2
+ class UuidModifier
3
+ class << self
4
+
5
+ def minimize(uuid)
6
+ uuid.delete('-')
7
+ end
8
+
9
+ def append(uuid, value)
10
+ "#{minimize(uuid)}/#{value}"
11
+ end
12
+
13
+ def reconstitute(id)
14
+ "#{id[0..7]}-#{id[8..11]}-#{id[12..15]}-#{id[16..19]}-#{id[20..31]}"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class StateValidator < ActiveModel::EachValidator
4
+ def validate_each(record, attribute, value)
5
+ return if value.nil? && options[:allow_nil]
6
+
7
+ correct_states = options[:only] || []
8
+ wrong_states = options[:except] || []
9
+ state_method = options.fetch(:state, :state)
10
+ current_state = attribute == state_method ? value : value&.send(state_method)
11
+ return if current_state.nil? && options[:allow_nil]
12
+
13
+ if (wrong_states.present? && wrong_states.include?(current_state)) || (correct_states.present? && correct_states.exclude?(current_state))
14
+ record.errors.add(attribute, I18n.t(attribute == state_method ? 'errors.messages.not_an_allowed_state' : 'errors.messages.not_in_an_allowed_state'))
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UnchangedValidator < ActiveModel::EachValidator
4
+ def validate_each(record, attribute, _value)
5
+ return unless record.persisted?
6
+
7
+ if record.changed_attributes.include?(attribute) || record.changed_attributes.include?("#{attribute}_id")
8
+ record.errors.add(attribute,
9
+ I18n.t('errors.messages.may_not_be_changed'))
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class YamlValidator < ActiveModel::EachValidator
4
+ def validate_each(record, attribute, value)
5
+ YAML.safe_load(value)
6
+ rescue Exception => e
7
+ record.errors.add attribute, e.message.gsub('(<unknown>)', 'invalid')
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auxilium
4
+ VERSION = "3.0.24"
5
+ end
data/lib/auxilium.rb ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'auxilium/version'
4
+ require 'active_support'
5
+ require 'active_model'
6
+ require 'pundit'
7
+ require 'responders'
8
+ require 'rolify'
9
+
10
+ require 'i18n'
11
+ I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'auxilium', 'locale', '*.{rb,yml}')]
12
+
13
+ require 'core_ext/string'
14
+ require 'auxilium/easy_crypt'
15
+ require 'auxilium/integer_chunker'
16
+ require 'auxilium/concerns'
17
+ require 'auxilium/concerns/admin_authenticated'
18
+ require 'auxilium/concerns/authenticated'
19
+ require 'auxilium/concerns/metadata'
20
+ require 'auxilium/concerns/metadata_scoped'
21
+ require 'auxilium/concerns/model_name_shortcuts'
22
+ require 'auxilium/responders/continue_responder'
23
+ require 'auxilium/responders/signum_responder'
24
+ require 'auxilium/responders/responder'
25
+ require 'auxilium/validators/state_validator'
26
+ require 'auxilium/validators/unchanged_validator'
27
+ require 'auxilium/validators/yaml_validator'
28
+ require 'auxilium/grape'
29
+ require 'auxilium/grape/parameter_filter'
30
+ require 'auxilium/uuid_modifier'
31
+
32
+ module Auxilium
33
+ class Error < StandardError; end
34
+ # Your code goes here...
35
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class String
4
+ def downcase_first
5
+ self[0] = self[0].downcase
6
+ self
7
+ end
8
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ namespace File.basename(Dir.pwd) do
6
+ desc 'Semantically version and release.\nArguments: PART[=patch] (other options are major and minor)'
7
+ task :semver do
8
+ versions = nil
9
+
10
+ gemspec = Dir.glob(File.expand_path(Dir.pwd) + '/*.gemspec').first
11
+ if gemspec
12
+ spec = Gem::Specification.load(gemspec)
13
+ versions = spec.version.to_s
14
+ end
15
+
16
+ version_file = Dir.glob(File.expand_path(Dir.pwd) + '/lib/**/version.rb').first
17
+ if version_file
18
+ version_file_content = File.read(version_file)
19
+ versions = version_file_content.scan(/VERSION\s=\s(\"|')(.*)(\"|')/).flatten[1] if versions.nil?
20
+ end
21
+
22
+ raise 'Unable to detect version' if versions.nil?
23
+
24
+ versions = versions.split('.').map(&:to_i)
25
+
26
+ part = ENV['PART'] || 'patch'
27
+ what = %w[ma mi pa].index(part.to_s[0, 2].downcase)
28
+ what ||= 2
29
+
30
+ new_version = versions.tap { |parts| parts[what] += 1 }
31
+ new_version = new_version.map.with_index { |v, i| i > what ? 0 : v }.join('.')
32
+
33
+ if version_file
34
+ File.open(version_file, 'w') do |file|
35
+ file.puts version_file_content.gsub(/VERSION\s=\s(\"|')(.*)(\"|')/, "VERSION = \"#{new_version}\"")
36
+ end
37
+
38
+ relative_version_path = Pathname.new(version_file).relative_path_from(Dir.pwd)
39
+ `git add #{relative_version_path}`
40
+ end
41
+
42
+ if File.exist?('./package.json')
43
+ package = JSON.parse(File.read('./package.json'))
44
+ package['version'] = new_version
45
+ File.open('./package.json', 'w') do |file|
46
+ file.puts(JSON.pretty_generate(package))
47
+ end
48
+
49
+ `git add ./package.json`
50
+ end
51
+
52
+ if gemspec
53
+ puts "Release #{spec.name} #{new_version}"
54
+ else
55
+ puts "Updated version to #{new_version}"
56
+ end
57
+
58
+ puts
59
+ puts "Changelog:"
60
+ puts `git log $(git describe --tags --abbrev=0)..HEAD --oneline`
61
+ puts
62
+ puts
63
+ `git commit -m "Version #{new_version}"`
64
+ `git push`
65
+ `git tag #{new_version}`
66
+ `git push --tags`
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auxilium
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.24
5
+ platform: ruby
6
+ authors:
7
+ - Andre Meij
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pundit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">"
60
+ - !ruby/object:Gem::Version
61
+ version: '2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">"
67
+ - !ruby/object:Gem::Version
68
+ version: '2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: responders
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">"
74
+ - !ruby/object:Gem::Version
75
+ version: '3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">"
81
+ - !ruby/object:Gem::Version
82
+ version: '3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rolify
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">"
88
+ - !ruby/object:Gem::Version
89
+ version: '5'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">"
95
+ - !ruby/object:Gem::Version
96
+ version: '5'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">"
109
+ - !ruby/object:Gem::Version
110
+ version: '5.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '12.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '12.0'
139
+ description: Utility classes that are to small to warrant a own gem for now.
140
+ email:
141
+ - andre@itsmeij.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".travis.yml"
148
+ - Gemfile
149
+ - Gemfile.lock
150
+ - LICENSE
151
+ - README.md
152
+ - Rakefile
153
+ - auxilium.gemspec
154
+ - bin/console
155
+ - bin/setup
156
+ - lib/auxilium.rb
157
+ - lib/auxilium/concerns.rb
158
+ - lib/auxilium/concerns/admin_authenticated.rb
159
+ - lib/auxilium/concerns/authenticated.rb
160
+ - lib/auxilium/concerns/metadata.rb
161
+ - lib/auxilium/concerns/metadata_scoped.rb
162
+ - lib/auxilium/concerns/model_name_shortcuts.rb
163
+ - lib/auxilium/easy_crypt.rb
164
+ - lib/auxilium/grape.rb
165
+ - lib/auxilium/grape/parameter_filter.rb
166
+ - lib/auxilium/integer_chunker.rb
167
+ - lib/auxilium/locale/en.yml
168
+ - lib/auxilium/responders/continue_responder.rb
169
+ - lib/auxilium/responders/responder.rb
170
+ - lib/auxilium/responders/signum_responder.rb
171
+ - lib/auxilium/uuid_modifier.rb
172
+ - lib/auxilium/validators/state_validator.rb
173
+ - lib/auxilium/validators/unchanged_validator.rb
174
+ - lib/auxilium/validators/yaml_validator.rb
175
+ - lib/auxilium/version.rb
176
+ - lib/core_ext/string.rb
177
+ - lib/tasks/semver.rake
178
+ homepage: https://code.entropydecelerator.com/components/auxilium
179
+ licenses: []
180
+ metadata:
181
+ homepage_uri: https://code.entropydecelerator.com/components/auxilium
182
+ source_code_uri: https://code.entropydecelerator.com/components/auxilium
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: 2.6.5
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubygems_version: 3.3.7
199
+ signing_key:
200
+ specification_version: 4
201
+ summary: Random utilities.
202
+ test_files: []