cotcube-helpers 0.2.3 → 0.2.4

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: 1d08ed5fa831283b0934d2ce7f86f9da0f1be5430d0d3164ee503b0aa7bac74f
4
- data.tar.gz: ac59b5558432299e6906c8a93b4ddab8b7a57a7cac4b2c11239a8f41a8c05f4e
3
+ metadata.gz: 569d3d98802f31608b3525e0b0692a19a67b65a05036f7b9c04cd4d8985017d3
4
+ data.tar.gz: ad92e036d65e317ab94f179020b4d131ebb085e8ff87395f17ac5c65b0ec02a2
5
5
  SHA512:
6
- metadata.gz: 8b3ce7871cbc2068523994caa155a2291512c0cce8c72398f51de275e56c6e1a75a94402327118f27ae0376ccbf70b148be3fb17d0f66326e019d21a639ae485
7
- data.tar.gz: e17fe32e700a3441e5e54a4b521c0c3d20acedbfb45606cd8f3da6edb5041a7cbcab522729da6d9d0e784f739730972af1ad1210b5542e06cd879f70587d7b1e
6
+ metadata.gz: ca30750b5450a285efc24f7d8498919b329fddc848e8eaee24990632701e529ab967aaf4c94d6718858f921297674adaaee36025a2fce2664d11e370e0003a86
7
+ data.tar.gz: 7b85764c5630f909f87c0987e662b6801e20e22de850945342dddc839a67c7636abe284463f4e5fba1c952aec80e51dce25f24a1795e9c9a6cdb96e8b29907e6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 0.2.4 (January 13, 2022)
2
+ - minor changes to init and bin/uncommitted
3
+ - datetime_ext: added #seconds_until_next_minute
4
+ - hash: added #deep_dup and #reduce_group; array: added #deep_dup
5
+ - bin/gitlog: pretty formatted git log
6
+ - string_ext: escape_regex escapes characters that otherwise have functional meanings in a regex
7
+ - array_ext: elem_raises? checks for each elem if raises with block, return raising elems or false
8
+ - Merge branch 'main' of github.com:donkeybridge/cotcube-helpers into main
9
+ - merging conflict
10
+
1
11
  ## 0.2.3 (December 30, 2021)
2
12
  - merging conflict
3
13
  - added bare josch_ and order_client s
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
data/bin/gitlog ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ GIT=`which git`
3
+ ${GIT} log --graph --pretty=format:'%N%h %<(100)%s (%cr) %d%n%b' --abbrev-commit | egrep '\\|/|\w+' | sed 's/^|/ /'
4
+
data/bin/uncommitted ADDED
@@ -0,0 +1,28 @@
1
+ #!/bin/bash
2
+ ROOT=${1:-$HOME/GEMS}
3
+
4
+
5
+ check_dir () {
6
+ CYAN="\033[1;36m"
7
+ RESET="\033[0m"
8
+ VGREP="grep --color=always -v"
9
+ dir=$1
10
+ if [ -d "${dir}/.git" ]; then
11
+ echo -e ${CYAN}${dir}${RESET}
12
+ pushd ${dir} 2>&1 >/dev/null
13
+ git status 2>&1 | $VGREP 'no changes added to commit' |\
14
+ $VGREP '^$' |\
15
+ $VGREP 'to include in what will' |\
16
+ $VGREP '(use "git ' |\
17
+ $VGREP 'On branch main' |\
18
+ $VGREP 'On branch master' |\
19
+ $VGREP 'nothing to commit' |\
20
+ $VGREP 'Your branch is up to date'
21
+ popd 2>&1 >/dev/null
22
+ fi
23
+ }
24
+
25
+
26
+ export -f check_dir
27
+
28
+ find $ROOT -type d -maxdepth 1 2>/dev/null | xargs -n 1 bash -c 'check_dir "$1"' _
@@ -64,38 +64,63 @@ class Array
64
64
  def select_within(ranges:, attr: nil, &block)
65
65
  unless attr.nil? || first[attr]
66
66
  raise ArgumentError,
67
- "At least first element of Array '#{first}' does not contain attr '#{attr}'!"
68
- end
69
- raise ArgumentError, 'Ranges should be an Array or, more precisely, respond_to :map' unless ranges.respond_to? :map
70
- raise ArgumentError, 'Each range in :ranges should respond to .include!' unless ranges.map do |x|
71
- x.respond_to? :include?
72
- end.reduce(:&)
73
-
74
- select do |el|
75
- value = attr.nil? ? el : el[attr]
76
- ranges.map do |range|
77
- range.include?(block.nil? ? value : block.call(value))
78
- end.reduce(:|)
67
+ "At least first element of Array '#{first}' does not contain attr '#{attr}'!"
68
+ end
69
+ raise ArgumentError, 'Ranges should be an Array or, more precisely, respond_to :map' unless ranges.respond_to? :map
70
+ raise ArgumentError, 'Each range in :ranges should respond to .include!' unless ranges.map do |x|
71
+ x.respond_to? :include?
72
+ end.reduce(:&)
73
+
74
+ select do |el|
75
+ value = attr.nil? ? el : el[attr]
76
+ ranges.map do |range|
77
+ range.include?(block.nil? ? value : block.call(value))
78
+ end.reduce(:|)
79
+ end
79
80
  end
80
- end
81
81
 
82
- def select_right_by(inclusive: false, exclusive: false, initial: [], &block)
83
- # unless range.is_a? Range and
84
- # (range.begin.nil? or range.begin.is_a?(Integer)) and
85
- # (range.end.nil? or range.end.is_a?(Integer))
86
- # raise ArgumentError, ":range, if given, must be a range of ( nil|Integer..nil|Integer), got '#{range}'"
87
- # end
82
+ def select_right_by(inclusive: false, exclusive: false, initial: [], &block)
83
+ # unless range.is_a? Range and
84
+ # (range.begin.nil? or range.begin.is_a?(Integer)) and
85
+ # (range.end.nil? or range.end.is_a?(Integer))
86
+ # raise ArgumentError, ":range, if given, must be a range of ( nil|Integer..nil|Integer), got '#{range}'"
87
+ # end
88
+
89
+ raise ArgumentError, 'No block given.' unless block.is_a? Proc
90
+
91
+ inclusive = true unless exclusive
92
+ if inclusive && exclusive
93
+ raise ArgumentError,
94
+ "Either :inclusive or :exclusive must remain falsey, got '#{inclusive}' and '#{exclusive}'"
95
+ end
96
+
97
+ index = find_index { |obj| block.call(obj) }
88
98
 
89
- raise ArgumentError, 'No block given.' unless block.is_a? Proc
99
+ self[((inclusive ? index : index + 1)..)]
100
+ end
90
101
 
91
- inclusive = true unless exclusive
92
- if inclusive && exclusive
93
- raise ArgumentError,
94
- "Either :inclusive or :exclusive must remain falsey, got '#{inclusive}' and '#{exclusive}'"
102
+ def elem_raises?(&block)
103
+ raise ArgumentError, "Must provide a block." unless block_given?
104
+ raise ArgumentError, "Block must have arity of 1." unless block.arity == 1
105
+ map do |elem|
106
+ begin
107
+ block.call(elem)
108
+ false
109
+ rescue
110
+ elem
111
+ end
112
+ end.reject{|z| z.is_a? FalseClass }.tap{|z| z.empty? ? (return false) : (return z)}
95
113
  end
96
114
 
97
- index = find_index { |obj| block.call(obj) }
115
+ def deep_dup
116
+ map do |el|
117
+ case el
118
+ when Hash, Array
119
+ el.deep_dup
120
+ else
121
+ el.dup
122
+ end
123
+ end
124
+ end
98
125
 
99
- self[((inclusive ? index : index + 1)..)]
100
- end
101
126
  end
@@ -12,6 +12,14 @@ class DateTime
12
12
  end
13
13
 
14
14
  alias to_sssm to_seconds_since_sunday_morning
15
+
16
+ def seconds_until_next_minute(offset: 60)
17
+ offset = offset % 60
18
+ offset = 60 if offset.zero?
19
+ seconds = (self + offset - (self.to_f % 60).round(3) - self).to_f
20
+ seconds + (seconds.negative? ? 60 : 0)
21
+ end
22
+
15
23
  end
16
24
 
17
25
  class Date
@@ -21,12 +29,12 @@ class Date
21
29
  form = '%Y %W %w'
22
30
  build_range = lambda {|w|
23
31
  begin
24
- ( DateTime.strptime("#{year} #{w} 1", form).to_date..
25
- DateTime.strptime("#{year} #{w} 0", form).to_date)
32
+ ( DateTime.strptime("#{year} #{w} 1", form).to_date..
33
+ DateTime.strptime("#{year} #{w} 0", form).to_date)
26
34
  rescue
27
- # beyond Dec 31st #strptime must be called with cw:0 to keep it working
28
- ( DateTime.strptime("#{year} #{w} 1", form).to_date..
29
- DateTime.strptime("#{year+1} 0 0", form).to_date)
35
+ # beyond Dec 31st #strptime must be called with cw:0 to keep it working
36
+ ( DateTime.strptime("#{year} #{w} 1", form).to_date..
37
+ DateTime.strptime("#{year+1} 0 0", form).to_date)
30
38
  end
31
39
  }
32
40
  case week
@@ -14,4 +14,30 @@ class Hash
14
14
  end
15
15
  self
16
16
  end
17
+
18
+ # a group_hash was created from an array by running group_by
19
+ # to reduce a group_hash, the given block is applied to each array of the hash
20
+ # if its not an array value, the block will auto-yield nil
21
+ def reduce_group(&block)
22
+ raise ArgumentError, 'No block given' unless block_given?
23
+ map do |key,value|
24
+ case value
25
+ when Array
26
+ [key, (block.call(value) rescue nil) ]
27
+ else
28
+ [key, nil]
29
+ end
30
+ end.to_h
31
+ end
32
+
33
+ def deep_dup
34
+ map do |k,v|
35
+ case v
36
+ when Hash, Array
37
+ [k, v.deep_dup]
38
+ else
39
+ [k, v.dup]
40
+ end
41
+ end.to_h
42
+ end
17
43
  end
@@ -22,9 +22,10 @@ module Cotcube
22
22
  def init(config_file_name: nil,
23
23
  gem_name: nil,
24
24
  debug: false)
25
- gem_name ||= self.ancestors.first.to_s
26
- config_file_name = "#{gem_name.downcase.split('::').last}.yml"
27
- config_file = config_path + "/#{config_file_name}"
25
+ gem_name ||= self.ancestors.first.to_s
26
+ name = gem_name.split('::').last.downcase
27
+ config_file_name = "#{name}.yml"
28
+ config_file = config_path + "/#{config_file_name}"
28
29
 
29
30
  if File.exist?(config_file)
30
31
  require 'yaml'
@@ -34,7 +35,8 @@ module Cotcube
34
35
  end
35
36
 
36
37
  defaults = {
37
- data_path: '/var/cotcube/' + name.split('::').last.downcase,
38
+ data_path: '/var/cotcube/' + name,
39
+ pid_file: "/var/run/cotcube/#{name}.pid"
38
40
  }
39
41
 
40
42
  config = defaults.merge(config)
@@ -10,5 +10,9 @@ class String
10
10
  false
11
11
  end
12
12
 
13
+ def escape_regex
14
+ chars.map{|z| %w[ . | ( ) [ ] { } \ ^ $ + * ? ].include?(z) ? "\\#{z}" : z }.join
15
+ end
16
+
13
17
  alias is_valid_json? valid_json?
14
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cotcube-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin L. Tischendorf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-30 00:00:00.000000000 Z
11
+ date: 2022-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -93,6 +93,8 @@ files:
93
93
  - LICENSE.txt
94
94
  - README.md
95
95
  - VERSION
96
+ - bin/gitlog
97
+ - bin/uncommitted
96
98
  - cotcube-helpers.gemspec
97
99
  - lib/cotcube-helpers.rb
98
100
  - lib/cotcube-helpers/array_ext.rb