ulid-rails 0.4.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 344d5b35daef598e2fe1116ad9bebea5d24cf9b6c1c2150344f2f1e5b25f0989
4
- data.tar.gz: ecf448dea0921bf022a7888d0f2b90f23e27f08b5e103f6aa3669e0f71b0913a
3
+ metadata.gz: b4ae7aa650be9d57249be6d2a1a3bf77bf26fdb14493533137d7296f07772410
4
+ data.tar.gz: 521af5d85b5b033b182678cd189ebbbbebf6e4571f2cfe076bcae4fa37800c6d
5
5
  SHA512:
6
- metadata.gz: 573a3e355e9487ccea553ce0041b831ba10d45d578906022ccbd99a9b672d9859d9cc9f1ae324bab61d68f9c0669609d1bfdfffe870d0a498309be876d6f68c8
7
- data.tar.gz: d59ccebd6290359ca5b1e1508275aa16eee8e061455a35cd29ee2439acf07cb777d9ca013b855abaaec0a08087aa2a23d05f43e710b2c313c782ca74e4a0fc82
6
+ metadata.gz: 7feebaa207e82b83fb213380f14df767216afb69ab8ee91d4ffd68495776d9b8c7f1ee2550f92ac5f7292b5b5c1511dc4a714cfa0671b2a7fe3528a15fb567b8
7
+ data.tar.gz: 886b465219c7fd77f57dad6c2c6c658149cfa22918ab7505863af86382beafbeb1d4616f02e1d13190fb14ab2044a95c8a9ca55bba6cbd87703c870e00c19284
data/.env ADDED
@@ -0,0 +1 @@
1
+ RUBY_VERSION=2.6
@@ -0,0 +1,15 @@
1
+ ---
2
+ name: Linting
3
+ on: [push, pull_request]
4
+ jobs:
5
+ standardrb:
6
+ env:
7
+ AR_VERSION: "5.2"
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+ - uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0
14
+ bundler-cache: true
15
+ - run: bundle exec standardrb
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: Tests
3
+ on: [push, pull_request]
4
+ jobs:
5
+ tests:
6
+ runs-on: ubuntu-latest
7
+ strategy:
8
+ matrix:
9
+ activerecord-version: ["5.2", "6.0", "6.1"]
10
+ ruby-version: ["2.6", "2.7", "3.0"]
11
+ exclude:
12
+ - activerecord-version: "5.2"
13
+ ruby-version: "3.0"
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Test ActiveRecord ${{ matrix.activerecord-version }} and Ruby ${{ matrix.ruby-version }}
17
+ run: RUBY_VERSION=${{ matrix.ruby-version }} docker-compose run -e AR_VERSION=${{ matrix.activerecord-version }} test
data/.standard.yml ADDED
@@ -0,0 +1 @@
1
+ ruby_version: 2.3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # ulid-rails CHANGELOG
2
2
 
3
+ ## 0.5
4
+
5
+ - Ensure ULID order respects timestamp order to millisecond precision.
6
+ - Validation of ULID format when setting value. A wrong format value will trigger a `ULID::Rails::ArgumentError`.
7
+
8
+ ## 0.4
9
+
10
+ - Support old ruby versions
11
+ - Fix auto_generate #2
12
+
3
13
  ## 0.3
4
14
 
5
15
  - Support PostgresQL
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in ulid-rails.gemspec
6
6
  gemspec
7
7
 
8
- version = ENV['AR_VERSION'] || '6.0'
9
- eval_gemfile File.expand_path("../gemfiles/#{version}.gemfile", __FILE__)
8
+ version = ENV["AR_VERSION"] || "6.0"
9
+ eval_gemfile File.expand_path("../gemfiles/#{version}.gemfile", __FILE__)
data/Rakefile CHANGED
@@ -7,4 +7,4 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.test_files = FileList["test/**/*_test.rb"]
8
8
  end
9
9
 
10
- task :default => :test
10
+ task default: :test
data/bin/run_tests CHANGED
@@ -9,17 +9,10 @@ test_with_db() {
9
9
 
10
10
  test_with_db "sqlite3"
11
11
 
12
- DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
12
+ test_with_db "mysql56"
13
13
 
14
- # Most features should work with MySQL 5.6 but I couldn't properly set it up in test.
15
- # $DIR/wait-for-it.sh mysql56:3306
16
- # test_with_db "mysql56"
17
-
18
- $DIR/wait-for-it.sh mysql57:3306
19
14
  test_with_db "mysql57"
20
15
 
21
- $DIR/wait-for-it.sh mysql80:3306
22
16
  test_with_db "mysql80"
23
17
 
24
- $DIR/wait-for-it.sh pg12:5432
25
18
  test_with_db "pg12"
data/docker-compose.yml CHANGED
@@ -1,13 +1,17 @@
1
1
  version: '3.6'
2
2
  services:
3
3
  test:
4
- image: ruby:2.6
4
+ image: "ruby:${RUBY_VERSION}"
5
5
  command: sh -c "rm -f Gemfile.lock && bundle install && bin/run_tests"
6
6
  depends_on:
7
- - mysql56
8
- - mysql57
9
- - mysql80
10
- - pg12
7
+ pg12:
8
+ condition: service_healthy
9
+ mysql56:
10
+ condition: service_healthy
11
+ mysql57:
12
+ condition: service_healthy
13
+ mysql80:
14
+ condition: service_healthy
11
15
  working_dir: /app
12
16
  volumes:
13
17
  - bundle:/usr/local/bundle
@@ -38,7 +42,8 @@ services:
38
42
  environment:
39
43
  PGDATA: /data
40
44
  POSTGRES_DB: db
45
+ POSTGRES_HOST_AUTH_METHOD: trust
41
46
  healthcheck:
42
- test: echo "\\l" | psql -U postgre
47
+ test: echo "\\l" | psql -U postgres
43
48
  volumes:
44
49
  bundle:
data/gemfiles/5.2.gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  gem "activesupport", "~> 5.2"
2
2
  gem "activemodel", "~> 5.2"
3
3
  gem "activerecord", "~> 5.2"
4
- gem 'sqlite3', '~> 1.3.6'
5
- gem 'mysql2'
6
- gem 'pg'
4
+ gem "sqlite3", "~> 1.3.6"
5
+ gem "mysql2"
6
+ gem "pg"
data/gemfiles/6.0.gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  gem "activesupport", "~> 6.0"
2
2
  gem "activemodel", "~> 6.0"
3
3
  gem "activerecord", "~> 6.0"
4
- gem 'sqlite3', '~> 1.4.1'
5
- gem 'mysql2'
6
- gem 'pg'
4
+ gem "sqlite3", "~> 1.4.1"
5
+ gem "mysql2"
6
+ gem "pg"
@@ -0,0 +1,6 @@
1
+ gem "activesupport", "~> 6.1.0"
2
+ gem "activemodel", "~> 6.1.0"
3
+ gem "activerecord", "~> 6.1.0"
4
+ gem "sqlite3", "~> 1.4.2"
5
+ gem "mysql2"
6
+ gem "pg"
@@ -0,0 +1,5 @@
1
+ module ULID
2
+ module Rails
3
+ class ArgumentError < StandardError; end
4
+ end
5
+ end
@@ -4,7 +4,7 @@ module ULID
4
4
  module Rails
5
5
  module Formatter
6
6
  def self.format(v)
7
- sanitized = v.delete('-').hex
7
+ sanitized = v.delete("-").hex
8
8
  Base32::Crockford.encode(sanitized).rjust(26, "0")
9
9
  end
10
10
 
@@ -4,8 +4,8 @@ module ULID
4
4
  module Migrations
5
5
  def virtual_ulid_timestamp(timestamp_column_name, ulid_column_name)
6
6
  virtual timestamp_column_name,
7
- type: :datetime,
8
- as: "FROM_UNIXTIME(CONV(HEX(#{ulid_column_name} >> 80), 16, 10) / 1000.0)"
7
+ type: :datetime,
8
+ as: "FROM_UNIXTIME(CONV(HEX(#{ulid_column_name} >> 80), 16, 10) / 1000.0)"
9
9
  end
10
10
  end
11
11
  end
@@ -1,5 +1,7 @@
1
1
  require "active_model/type"
2
2
  require "ulid/rails/formatter"
3
+ require "ulid/rails/validator"
4
+ require "ulid/rails/errors"
3
5
 
4
6
  module ULID
5
7
  module Rails
@@ -8,16 +10,21 @@ module ULID
8
10
  alias_method :hex, :to_s
9
11
  end
10
12
 
11
- def initialize(formatter = Formatter)
13
+ def initialize(formatter = Formatter, validator = Validator)
12
14
  @formatter = formatter
15
+ @validator = validator
13
16
  super()
14
17
  end
15
18
 
16
- def cast(value)
19
+ def assert_valid_value(value)
20
+ raise ArgumentError, "`#{value}` is not a ULID format" unless @validator.is_valid?(value)
21
+ end
22
+
23
+ def deserialize(value)
17
24
  return nil if value.nil?
18
25
 
19
26
  value = value.to_s if value.is_a?(Data)
20
- value = value.unpack("H*")[0] if value.encoding == Encoding::ASCII_8BIT
27
+ value = value.unpack1("H*") if value.encoding == Encoding::ASCII_8BIT
21
28
  value = value[2..-1] if value.start_with?("\\x")
22
29
 
23
30
  value.length == 32 ? @formatter.format(value) : super
@@ -26,13 +33,23 @@ module ULID
26
33
  def serialize(value)
27
34
  return if value.nil?
28
35
 
29
- case ActiveRecord::Base.connection_config[:adapter]
36
+ case adapter
30
37
  when "mysql2", "sqlite3"
31
38
  Data.new(@formatter.unformat(value))
32
39
  when "postgresql"
33
40
  Data.new([@formatter.unformat(value)].pack("H*"))
34
41
  end
35
42
  end
43
+
44
+ private
45
+
46
+ def adapter
47
+ if ::ActiveRecord::Base.respond_to?(:connection_db_config)
48
+ ::ActiveRecord::Base.connection_db_config.configuration_hash[:adapter]
49
+ else
50
+ ::ActiveRecord::Base.connection_config[:adapter]
51
+ end
52
+ end
36
53
  end
37
54
  end
38
55
  end
@@ -0,0 +1,12 @@
1
+ require "base32/crockford"
2
+
3
+ module ULID
4
+ module Rails
5
+ module Validator
6
+ def self.is_valid?(v)
7
+ return true if v.nil?
8
+ v.length == 26 && Base32::Crockford.valid?(v)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  module ULID
2
2
  module Rails
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
data/lib/ulid/rails.rb CHANGED
@@ -15,7 +15,7 @@ module ULID
15
15
  def ulid(column_name, primary_key: false, auto_generate: nil)
16
16
  attribute column_name, ULID::Rails::Type.new
17
17
 
18
- auto_generate = primary_key ? primary_key : auto_generate
18
+ auto_generate = primary_key || auto_generate
19
19
  if auto_generate
20
20
  before_create do
21
21
  send("#{column_name}=", ULID.generate) if send(column_name).nil?
@@ -25,7 +25,11 @@ module ULID
25
25
 
26
26
  def ulid_extract_timestamp(ulid_column, timestamp_column = :created_at)
27
27
  define_method timestamp_column do
28
- at = super() rescue nil
28
+ at = begin
29
+ super()
30
+ rescue
31
+ nil
32
+ end
29
33
  if !at && (id_val = send(ulid_column))
30
34
  Time.zone.at((Base32::Crockford.decode(id_val) >> 80) / 1000.0)
31
35
  else
data/ulid-rails.gemspec CHANGED
@@ -3,22 +3,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require "ulid/rails/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "ulid-rails"
7
- spec.version = ULID::Rails::VERSION
8
- spec.authors = ["Kazunori Kajihiro"]
9
- spec.email = ["kazunori.kajihiro@gmail.com"]
6
+ spec.name = "ulid-rails"
7
+ spec.version = ULID::Rails::VERSION
8
+ spec.authors = ["Kazunori Kajihiro", "Zendesk"]
9
+ spec.email = ["kazunori.kajihiro@gmail.com", "ruby-core@zendesk.com"]
10
10
 
11
- spec.summary = %q{ULID for rails}
12
- spec.description = %q{ULID for rails}
13
- spec.license = "MIT"
11
+ spec.summary = "ULID for rails"
12
+ spec.description = "ULID for rails"
13
+ spec.license = "MIT"
14
14
 
15
15
  # Specify which files should be added to the gem when it is released.
16
16
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
18
18
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
19
  end
20
- spec.bindir = "exe"
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
24
  spec.add_dependency "ulid", "~> 1.0"
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "bundler"
30
30
  spec.add_development_dependency "rake"
31
31
  spec.add_development_dependency "minitest", "~> 5.0"
32
+ spec.add_development_dependency "standard", "~> 1.3.0"
32
33
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ulid-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazunori Kajihiro
8
- autorequire:
8
+ - Zendesk
9
+ autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2020-01-21 00:00:00.000000000 Z
12
+ date: 2021-10-25 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: ulid
@@ -122,15 +123,33 @@ dependencies:
122
123
  - - "~>"
123
124
  - !ruby/object:Gem::Version
124
125
  version: '5.0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: standard
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: 1.3.0
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: 1.3.0
125
140
  description: ULID for rails
126
141
  email:
127
142
  - kazunori.kajihiro@gmail.com
143
+ - ruby-core@zendesk.com
128
144
  executables: []
129
145
  extensions: []
130
146
  extra_rdoc_files: []
131
147
  files:
148
+ - ".env"
149
+ - ".github/workflows/lint.yml"
150
+ - ".github/workflows/test.yml"
132
151
  - ".gitignore"
133
- - ".travis.yml"
152
+ - ".standard.yml"
134
153
  - CHANGELOG.md
135
154
  - Gemfile
136
155
  - LICENSE.txt
@@ -139,21 +158,23 @@ files:
139
158
  - bin/console
140
159
  - bin/run_tests
141
160
  - bin/setup
142
- - bin/wait-for-it.sh
143
161
  - docker-compose.yml
144
162
  - gemfiles/5.2.gemfile
145
163
  - gemfiles/6.0.gemfile
164
+ - gemfiles/6.1.gemfile
146
165
  - lib/ulid/rails.rb
166
+ - lib/ulid/rails/errors.rb
147
167
  - lib/ulid/rails/formatter.rb
148
168
  - lib/ulid/rails/patch.rb
149
169
  - lib/ulid/rails/type.rb
170
+ - lib/ulid/rails/validator.rb
150
171
  - lib/ulid/rails/version.rb
151
172
  - ulid-rails.gemspec
152
- homepage:
173
+ homepage:
153
174
  licenses:
154
175
  - MIT
155
176
  metadata: {}
156
- post_install_message:
177
+ post_install_message:
157
178
  rdoc_options: []
158
179
  require_paths:
159
180
  - lib
@@ -168,9 +189,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
189
  - !ruby/object:Gem::Version
169
190
  version: '0'
170
191
  requirements: []
171
- rubyforge_project:
172
- rubygems_version: 2.7.6
173
- signing_key:
192
+ rubyforge_project:
193
+ rubygems_version: 2.7.6.3
194
+ signing_key:
174
195
  specification_version: 4
175
196
  summary: ULID for rails
176
197
  test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.5.1
7
- before_install: gem install bundler -v 1.16.4
data/bin/wait-for-it.sh DELETED
@@ -1,178 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Use this script to test if a given TCP host/port are available
3
-
4
- WAITFORIT_cmdname=${0##*/}
5
-
6
- echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
7
-
8
- usage()
9
- {
10
- cat << USAGE >&2
11
- Usage:
12
- $WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
13
- -h HOST | --host=HOST Host or IP under test
14
- -p PORT | --port=PORT TCP port under test
15
- Alternatively, you specify the host and port as host:port
16
- -s | --strict Only execute subcommand if the test succeeds
17
- -q | --quiet Don't output any status messages
18
- -t TIMEOUT | --timeout=TIMEOUT
19
- Timeout in seconds, zero for no timeout
20
- -- COMMAND ARGS Execute command with args after the test finishes
21
- USAGE
22
- exit 1
23
- }
24
-
25
- wait_for()
26
- {
27
- if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
28
- echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
29
- else
30
- echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
31
- fi
32
- WAITFORIT_start_ts=$(date +%s)
33
- while :
34
- do
35
- if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
36
- nc -z $WAITFORIT_HOST $WAITFORIT_PORT
37
- WAITFORIT_result=$?
38
- else
39
- (echo > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
40
- WAITFORIT_result=$?
41
- fi
42
- if [[ $WAITFORIT_result -eq 0 ]]; then
43
- WAITFORIT_end_ts=$(date +%s)
44
- echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
45
- break
46
- fi
47
- sleep 1
48
- done
49
- return $WAITFORIT_result
50
- }
51
-
52
- wait_for_wrapper()
53
- {
54
- # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
55
- if [[ $WAITFORIT_QUIET -eq 1 ]]; then
56
- timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
57
- else
58
- timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
59
- fi
60
- WAITFORIT_PID=$!
61
- trap "kill -INT -$WAITFORIT_PID" INT
62
- wait $WAITFORIT_PID
63
- WAITFORIT_RESULT=$?
64
- if [[ $WAITFORIT_RESULT -ne 0 ]]; then
65
- echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
66
- fi
67
- return $WAITFORIT_RESULT
68
- }
69
-
70
- # process arguments
71
- while [[ $# -gt 0 ]]
72
- do
73
- case "$1" in
74
- *:* )
75
- WAITFORIT_hostport=(${1//:/ })
76
- WAITFORIT_HOST=${WAITFORIT_hostport[0]}
77
- WAITFORIT_PORT=${WAITFORIT_hostport[1]}
78
- shift 1
79
- ;;
80
- --child)
81
- WAITFORIT_CHILD=1
82
- shift 1
83
- ;;
84
- -q | --quiet)
85
- WAITFORIT_QUIET=1
86
- shift 1
87
- ;;
88
- -s | --strict)
89
- WAITFORIT_STRICT=1
90
- shift 1
91
- ;;
92
- -h)
93
- WAITFORIT_HOST="$2"
94
- if [[ $WAITFORIT_HOST == "" ]]; then break; fi
95
- shift 2
96
- ;;
97
- --host=*)
98
- WAITFORIT_HOST="${1#*=}"
99
- shift 1
100
- ;;
101
- -p)
102
- WAITFORIT_PORT="$2"
103
- if [[ $WAITFORIT_PORT == "" ]]; then break; fi
104
- shift 2
105
- ;;
106
- --port=*)
107
- WAITFORIT_PORT="${1#*=}"
108
- shift 1
109
- ;;
110
- -t)
111
- WAITFORIT_TIMEOUT="$2"
112
- if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
113
- shift 2
114
- ;;
115
- --timeout=*)
116
- WAITFORIT_TIMEOUT="${1#*=}"
117
- shift 1
118
- ;;
119
- --)
120
- shift
121
- WAITFORIT_CLI=("$@")
122
- break
123
- ;;
124
- --help)
125
- usage
126
- ;;
127
- *)
128
- echoerr "Unknown argument: $1"
129
- usage
130
- ;;
131
- esac
132
- done
133
-
134
- if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
135
- echoerr "Error: you need to provide a host and port to test."
136
- usage
137
- fi
138
-
139
- WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
140
- WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
141
- WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
142
- WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
143
-
144
- # check to see if timeout is from busybox?
145
- WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
146
- WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
147
- if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
148
- WAITFORIT_ISBUSY=1
149
- WAITFORIT_BUSYTIMEFLAG="-t"
150
-
151
- else
152
- WAITFORIT_ISBUSY=0
153
- WAITFORIT_BUSYTIMEFLAG=""
154
- fi
155
-
156
- if [[ $WAITFORIT_CHILD -gt 0 ]]; then
157
- wait_for
158
- WAITFORIT_RESULT=$?
159
- exit $WAITFORIT_RESULT
160
- else
161
- if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
162
- wait_for_wrapper
163
- WAITFORIT_RESULT=$?
164
- else
165
- wait_for
166
- WAITFORIT_RESULT=$?
167
- fi
168
- fi
169
-
170
- if [[ $WAITFORIT_CLI != "" ]]; then
171
- if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
172
- echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
173
- exit $WAITFORIT_RESULT
174
- fi
175
- exec "${WAITFORIT_CLI[@]}"
176
- else
177
- exit $WAITFORIT_RESULT
178
- fi