wspc-rails-extensions 1.0.2
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 +7 -0
- data/.gitignore +60 -0
- data/README.md +1 -0
- data/lib/rails_extensions/active_record/query_methods.rb +30 -0
- data/lib/rails_extensions/date.rb +5 -0
- data/lib/rails_extensions/enumerable.rb +37 -0
- data/lib/rails_extensions/integer.rb +9 -0
- data/lib/rails_extensions/numeric.rb +7 -0
- data/lib/rails_extensions/string.rb +32 -0
- data/lib/rails_extensions/version.rb +5 -0
- data/lib/wspc-rails-extensions.rb +6 -0
- data/wspc-rails-extensions.gemspec +18 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dc4a750bbc199408ca282889ea86d6d59267ecb4281abd95f41c6a7c8d51e595
|
4
|
+
data.tar.gz: 7198f62f37650b02f9fd6cf08dc5b415ab80f950c27595aed45801a82d1b73fd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9e06a65488aa8ddfd748d21b7d29d13f445cbefde2696b1b730437b21fdc88f02e9302df0491fa4aa00edc8d9012dc85c0af32fd7a742a3586c77df51d06d31e
|
7
|
+
data.tar.gz: 246d6244e11860b4cfbeb7e9524c15e6281bda9aa59f6fa7cf959f8f80661ed2ba945a32e98954fa32564c479da8d5c8e3b1ca72cfb88eaa60d041fa3d5eab73
|
data/.gitignore
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
57
|
+
|
58
|
+
# IDE files
|
59
|
+
/.idea/
|
60
|
+
/.vscode/
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# rails-extensions
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# implements new query methods from rails 7.0.4
|
4
|
+
|
5
|
+
module ActiveRecord
|
6
|
+
module QueryMethods
|
7
|
+
class WhereChain
|
8
|
+
def associated(*associations)
|
9
|
+
associations.each do |association|
|
10
|
+
reflection = scope_association_reflection(association)
|
11
|
+
@scope.joins!(association)
|
12
|
+
self.not(association => { reflection.association_primary_key => nil })
|
13
|
+
end
|
14
|
+
|
15
|
+
@scope
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def scope_association_reflection(association)
|
21
|
+
reflection = @scope.klass._reflect_on_association(association)
|
22
|
+
unless reflection
|
23
|
+
raise ArgumentError, "An association named `:#{association}` does not exist on the model `#{@scope.name}`."
|
24
|
+
end
|
25
|
+
|
26
|
+
reflection
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Enumerable
|
4
|
+
# Calculates a mean of the elements in the enumerable.
|
5
|
+
# [1, 2, 3, 4, 5].mean # => 3.0
|
6
|
+
def mean(init = 0.0, &block)
|
7
|
+
return init if empty?
|
8
|
+
|
9
|
+
if block_given?
|
10
|
+
map(&block).mean(init)
|
11
|
+
else
|
12
|
+
sum(init) / size.to_f
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Calculates the position of values allowing gaps. The return value is an array
|
17
|
+
# of arrays, each containing the original value and its position.
|
18
|
+
# If each values has an identifier, set the identifier as the first element of value
|
19
|
+
# and use with_identifier parameter.
|
20
|
+
# {a:2, b:3, c:5, d:2}.with_gap_index(with_identifier: true) # =>
|
21
|
+
# [[:a, 2, 0], [:d, 2, 0], [:b, 3, 2], [:c, 5, 3]]
|
22
|
+
def with_gap_index(offset = 0, with_identifier: false, &block)
|
23
|
+
if block_given?
|
24
|
+
map(&block).with_gap_index(offset, with_identifier: with_identifier)
|
25
|
+
else
|
26
|
+
new_array = []
|
27
|
+
current_pos = offset
|
28
|
+
|
29
|
+
each_with_index do |ele, idx|
|
30
|
+
same_as_previous = with_identifier ? ele.second == self[idx - 1].second : ele == self[idx - 1]
|
31
|
+
current_pos = idx + offset unless same_as_previous
|
32
|
+
new_array.push([ele, current_pos].flatten)
|
33
|
+
end
|
34
|
+
new_array
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class String
|
2
|
+
def normalize_string(regex = /[^\w.]/, replacement = ' ')
|
3
|
+
I18n.transliterate(self)
|
4
|
+
.gsub(regex, replacement)
|
5
|
+
.squish
|
6
|
+
.downcase
|
7
|
+
end
|
8
|
+
|
9
|
+
def strict_normalize_string
|
10
|
+
normalize_string(/[^A-Za-z0-9]/, '')
|
11
|
+
end
|
12
|
+
|
13
|
+
def pluralizes(count)
|
14
|
+
split(' ')
|
15
|
+
.map { |s| s.pluralize(count) }
|
16
|
+
.join(' ')
|
17
|
+
end
|
18
|
+
|
19
|
+
def true?
|
20
|
+
to_s.downcase == 'true'
|
21
|
+
end
|
22
|
+
|
23
|
+
# module to override basic String methods
|
24
|
+
module StringExtensions
|
25
|
+
def pluralize(count = nil, locale = :en)
|
26
|
+
return dup if count == 0
|
27
|
+
|
28
|
+
super(count, locale)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
String.prepend(StringExtensions)
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'lib/rails_extensions/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'wspc-rails-extensions'
|
5
|
+
s.version = RailsExtensions::VERSION
|
6
|
+
s.authors = ['Winespace']
|
7
|
+
s.email = ['contact@winespace.fr']
|
8
|
+
|
9
|
+
s.summary = 'Winespace Rails Extensions'
|
10
|
+
s.homepage = 'https://github.com/winespacefr/rails-extensions'
|
11
|
+
s.metadata = { 'source_code_uri' => 'https://github.com/winespacefr/rails-extensions' }
|
12
|
+
s.license = 'MIT'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
|
16
|
+
s.required_ruby_version = '>= 2.6'
|
17
|
+
s.add_runtime_dependency 'rails', '~> 6.0'
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wspc-rails-extensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Winespace
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
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:
|
28
|
+
email:
|
29
|
+
- contact@winespace.fr
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- README.md
|
36
|
+
- lib/rails_extensions/active_record/query_methods.rb
|
37
|
+
- lib/rails_extensions/date.rb
|
38
|
+
- lib/rails_extensions/enumerable.rb
|
39
|
+
- lib/rails_extensions/integer.rb
|
40
|
+
- lib/rails_extensions/numeric.rb
|
41
|
+
- lib/rails_extensions/string.rb
|
42
|
+
- lib/rails_extensions/version.rb
|
43
|
+
- lib/wspc-rails-extensions.rb
|
44
|
+
- wspc-rails-extensions.gemspec
|
45
|
+
homepage: https://github.com/winespacefr/rails-extensions
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata:
|
49
|
+
source_code_uri: https://github.com/winespacefr/rails-extensions
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '2.6'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubygems_version: 3.1.4
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Winespace Rails Extensions
|
69
|
+
test_files: []
|