pg_like 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: 517e8d85f6aaf3915c05456bd1f212f32bf3a672806e5114bf03ff46acfafbc3
4
+ data.tar.gz: a0be95f266d71b73decb3abe9e620e5c1b8e47913fca09039fcc68ab6d63556d
5
+ SHA512:
6
+ metadata.gz: 06cc11857daf049290a00fe578aeb74e2fff30ab08796e76260e6cdf1953b785c76b6b5c2388249f4a689ef937b1a97f44e8130d1be773705065b83323db589f
7
+ data.tar.gz: 912868702dbe3e71e1cb37cac3a2bd396640cdd1944ff09ba246531aeafa81e980a52cf9825777b316bb0dd21248455cc277c334ef082afbb80e63cf095f26ff
@@ -0,0 +1,24 @@
1
+ # [Choice] Ruby version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.1, 3.0, 2, 2.7, 2.6, 3-bullseye, 3.1-bullseye, 3.0-bullseye, 2-bullseye, 2.7-bullseye, 2.6-bullseye, 3-buster, 3.1-buster, 3.0-buster, 2-buster, 2.7-buster, 2.6-buster
2
+ ARG VARIANT=3.1-bullseye
3
+ FROM mcr.microsoft.com/vscode/devcontainers/ruby:0-${VARIANT}
4
+
5
+ # Install Rails
6
+ RUN gem install rails webdrivers
7
+
8
+ # Default value to allow debug server to serve content over GitHub Codespace's port forwarding service
9
+ # The value is a comma-separated list of allowed domains
10
+ ENV RAILS_DEVELOPMENT_HOSTS=".githubpreview.dev"
11
+
12
+ # [Choice] Node.js version: lts/*, 16, 14, 12, 10
13
+ ARG NODE_VERSION="lts/*"
14
+ RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"
15
+
16
+ # [Optional] Uncomment this section to install additional OS packages.
17
+ # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
18
+ # && apt-get -y install --no-install-recommends <your-package-list-here>
19
+
20
+ # [Optional] Uncomment this line to install additional gems.
21
+ # RUN gem install <your-gem-names-here>
22
+
23
+ # [Optional] Uncomment this line to install global node packages.
24
+ # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
@@ -0,0 +1,3 @@
1
+ CREATE USER vscode CREATEDB;
2
+ CREATE DATABASE vscode WITH OWNER vscode;
3
+ CREATE DATABASE pg_like_test WITH OWNER vscode;
@@ -0,0 +1,30 @@
1
+ // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2
+ // https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/ruby-rails-postgres
3
+ // Update the VARIANT arg in docker-compose.yml to pick a Ruby version
4
+ {
5
+ "name": "Ruby on Rails & Postgres",
6
+ "dockerComposeFile": "docker-compose.yml",
7
+ "service": "app",
8
+ "workspaceFolder": "/workspace",
9
+
10
+ // Configure tool-specific properties.
11
+ "customizations": {
12
+ // Configure properties specific to VS Code.
13
+ "vscode": {
14
+ // Add the IDs of extensions you want installed when the container is created.
15
+ "extensions": [
16
+ "rebornix.Ruby"
17
+ ]
18
+ }
19
+ },
20
+
21
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
22
+ // This can be used to network with other containers or the host.
23
+ // "forwardPorts": [3000, 5432],
24
+
25
+ // Use 'postCreateCommand' to run commands after the container is created.
26
+ "postCreateCommand": "bundle install",
27
+
28
+ // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
29
+ "remoteUser": "vscode"
30
+ }
@@ -0,0 +1,44 @@
1
+ version: '3'
2
+
3
+ services:
4
+ app:
5
+ build:
6
+ context: ..
7
+ dockerfile: .devcontainer/Dockerfile
8
+ args:
9
+ # Update 'VARIANT' to pick a version of Ruby: 3, 3.1, 3.0, 2, 2.7, 2.6
10
+ # Append -bullseye or -buster to pin to an OS version.
11
+ # Use -bullseye variants on local arm64/Apple Silicon.
12
+ VARIANT: "3.0"
13
+ # Optional Node.js version to install
14
+ NODE_VERSION: "14"
15
+
16
+ volumes:
17
+ - ..:/workspace:cached
18
+
19
+ # Overrides default command so things don't shut down after the process ends.
20
+ command: sleep infinity
21
+
22
+ # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
23
+ network_mode: service:db
24
+ # Uncomment the next line to use a non-root user for all processes.
25
+ # user: vscode
26
+
27
+ # Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
28
+ # (Adding the "ports" property to this file will not forward from a Codespace.)
29
+
30
+ db:
31
+ image: postgres:latest
32
+ restart: unless-stopped
33
+ volumes:
34
+ - postgres-data:/var/lib/postgresql/data
35
+ - ./create-db-user.sql:/docker-entrypoint-initdb.d/create-db-user.sql
36
+ environment:
37
+ POSTGRES_USER: postgres
38
+ POSTGRES_DB: postgres
39
+ POSTGRES_PASSWORD: postgres
40
+ # Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
41
+ # (Adding the "ports" property to this file will not forward from a Codespace.)
42
+
43
+ volumes:
44
+ postgres-data: null
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-11-06
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in pg_like.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pg_like (0.1.0)
5
+ activerecord (>= 5.2, < 8.0)
6
+ pg (>= 0.19, < 2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (7.0.4)
12
+ activesupport (= 7.0.4)
13
+ activerecord (7.0.4)
14
+ activemodel (= 7.0.4)
15
+ activesupport (= 7.0.4)
16
+ activesupport (7.0.4)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ tzinfo (~> 2.0)
21
+ ast (2.4.2)
22
+ concurrent-ruby (1.1.10)
23
+ database_cleaner (1.99.0)
24
+ i18n (1.12.0)
25
+ concurrent-ruby (~> 1.0)
26
+ json (2.6.2)
27
+ minitest (5.16.3)
28
+ parallel (1.22.1)
29
+ parser (3.1.2.1)
30
+ ast (~> 2.4.1)
31
+ pg (1.4.4)
32
+ rainbow (3.1.1)
33
+ rake (13.0.6)
34
+ regexp_parser (2.6.0)
35
+ rexml (3.2.5)
36
+ rubocop (1.38.0)
37
+ json (~> 2.3)
38
+ parallel (~> 1.10)
39
+ parser (>= 3.1.2.1)
40
+ rainbow (>= 2.2.2, < 4.0)
41
+ regexp_parser (>= 1.8, < 3.0)
42
+ rexml (>= 3.2.5, < 4.0)
43
+ rubocop-ast (>= 1.23.0, < 2.0)
44
+ ruby-progressbar (~> 1.7)
45
+ unicode-display_width (>= 1.4.0, < 3.0)
46
+ rubocop-ast (1.23.0)
47
+ parser (>= 3.1.1.0)
48
+ ruby-progressbar (1.11.0)
49
+ tzinfo (2.0.5)
50
+ concurrent-ruby (~> 1.0)
51
+ unicode-display_width (2.3.0)
52
+ with_model (2.1.6)
53
+ activerecord (>= 5.2)
54
+
55
+ PLATFORMS
56
+ x86_64-linux
57
+
58
+ DEPENDENCIES
59
+ bundler
60
+ database_cleaner (~> 1.5)
61
+ minitest (~> 5.0)
62
+ pg_like!
63
+ rake (~> 13.0)
64
+ rubocop (~> 1.21)
65
+ with_model (~> 2.0)
66
+
67
+ BUNDLED WITH
68
+ 2.2.33
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Victor
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,39 @@
1
+ # PgLike
2
+
3
+ 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/pg_like`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'pg_like'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install pg_like
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. Then, run `rake test` to run the tests. 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]/pg_like.
36
+
37
+ ## License
38
+
39
+ 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,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ #require "rubocop/rake_task"
13
+
14
+ #RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "pg_like"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ 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,35 @@
1
+ module PgLike
2
+ module Scopes
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ scope :like_any, lambda { |field, terms = nil, criterea: :both, unaccent: true|
6
+ terms = [terms] unless terms.is_a?(Array)
7
+ terms = terms.map(&:downcase)
8
+ terms = terms.map do |string|
9
+ string.prepend('%') if %i[both starts_with].include?(criterea.to_sym)
10
+ string.concat('%') if %i[both ends_with].include?(criterea.to_sym)
11
+ unaccent ? "UNACCENT('#{string}')" : "'#{string}'"
12
+ end
13
+ left_clause = "LOWER(#{field})"
14
+ left_clause = "UNACCENT(#{left_clause})" if unaccent
15
+ right_clause = "(array[#{terms.join(', ')}])"
16
+ where("#{left_clause} LIKE ANY #{right_clause}")
17
+ }
18
+
19
+ scope :like_all, lambda { |field, terms = nil, criterea: :both, unaccent: true|
20
+ terms = [terms] unless terms.is_a?(Array)
21
+ terms = terms.map(&:downcase)
22
+ terms = terms.map do |string|
23
+ string.prepend('%') if %i[both starts_with].include?(criterea.to_sym)
24
+ string.concat('%') if %i[both ends_with].include?(criterea.to_sym)
25
+ unaccent ? "UNACCENT('#{string}')" : "'#{string}'"
26
+ end
27
+ left_clause = "LOWER(#{field})"
28
+ left_clause = "UNACCENT(#{left_clause})" if unaccent
29
+ right_clause = "(array[#{terms.join(', ')}])"
30
+ where("#{left_clause} LIKE ALL #{right_clause}")
31
+ }
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgLike
4
+ VERSION = "0.1.0"
5
+ end
data/lib/pg_like.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "pg_like/version"
4
+ require "active_record"
5
+ require "pg_like/scopes"
6
+ module PgLike
7
+ # Your code goes here...
8
+ end
data/sig/pg_like.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module PgLike
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pg_like
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lapps Dev
8
+ - Victor Matheus
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2022-11-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '5.2'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '8.0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: '5.2'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '8.0'
34
+ - !ruby/object:Gem::Dependency
35
+ name: pg
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0.19'
41
+ - - "<"
42
+ - !ruby/object:Gem::Version
43
+ version: '2'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0.19'
51
+ - - "<"
52
+ - !ruby/object:Gem::Version
53
+ version: '2'
54
+ - !ruby/object:Gem::Dependency
55
+ name: bundler
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rake
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '10.0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: database_cleaner
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.5'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.5'
96
+ - !ruby/object:Gem::Dependency
97
+ name: with_model
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '2.0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '2.0'
110
+ description: A gem to facilitate the use of LIKE ANY and LIKE ALL PostgreSQL operators
111
+ with Rails ActiveRecord
112
+ email:
113
+ - contato@lapps.dev
114
+ - imatheusfsantos@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".devcontainer/Dockerfile"
120
+ - ".devcontainer/create-db-user.sql"
121
+ - ".devcontainer/devcontainer.json"
122
+ - ".devcontainer/docker-compose.yml"
123
+ - ".rubocop.yml"
124
+ - CHANGELOG.md
125
+ - Gemfile
126
+ - Gemfile.lock
127
+ - LICENSE.txt
128
+ - README.md
129
+ - Rakefile
130
+ - bin/console
131
+ - bin/setup
132
+ - lib/pg_like.rb
133
+ - lib/pg_like/scopes.rb
134
+ - lib/pg_like/version.rb
135
+ - sig/pg_like.rbs
136
+ homepage: https://github.com/lappsdev/pg_like
137
+ licenses:
138
+ - MIT
139
+ metadata:
140
+ homepage_uri: https://github.com/lappsdev/pg_like
141
+ source_code_uri: https://github.com/lappsdev/pg_like
142
+ changelog_uri: https://github.com/lappsdev/pg_like/blob/master/CHANGELOG.md
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: 2.0.0
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubygems_version: 3.2.33
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: LIKE ANY and LIKE ALL PostgreSQL operators with Rails
162
+ test_files: []