l42_my_ruby 0.1.0 → 0.1.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: 563696947db36797e95a7d9c02655e308161e19fdeec35aeb1f83c8bb6a9ec86
4
- data.tar.gz: 843a706a3e0f6c1eadb27f717167144aba4ac6ad8aca5ae9fffa9841cf4272be
3
+ metadata.gz: 1781982f07cea572f852c3a439fe867c61140a78ddcff1ee521188a60d8a97ba
4
+ data.tar.gz: 754a7ff931346db195b9d25fc1adf8cc63661101527ba8139e46147a36bb207e
5
5
  SHA512:
6
- metadata.gz: 334ad3440abce36b1743b06f0150995e2121e8ebd951ac84d8707857f6cbed1047c099b89c60cfc98ddadc65a56ff3a6bdf08ac8a0be3a2d66ff5cf82c743dac
7
- data.tar.gz: 1d8248b6a3dac274227a675cceec2fd8057c9fdc006ef4e725c2b2528888bad715585211bb6c28f3249a7665914aca22f0410253b86bb8f72ea57040b38487ff
6
+ metadata.gz: 871de02165537b8076e4280371c91db464d16f4c56e1acf52fcefcfc800d2f8d7ee735e0ea9847e70a7233241d2c64a1044e1b1db5df113933dd86611d91e855
7
+ data.tar.gz: 4f81c78b9444c3e129d18dda9c4f60743eb7993e1730021bf92bb99bcb67faedcbdaa6320afd66f21a36039daa0352a14e757ee52c93e667b3e86e67fc5eedda
data/README.md CHANGED
@@ -1,3 +1,8 @@
1
+ [![CI](https://github.com/robertdober/l42_my_ruby/workflows/CI/badge.svg)](https://github.com/robertdober/l42_my_ruby/actions)
2
+ [![Coverage Status](https://coveralls.io/repos/github/RobertDober/l42_my_ruby/badge.svg?branch=master)](https://coveralls.io/github/RobertDober/l42_my_ruby?branch=master)
3
+ [![Gem Version](https://badge.fury.io/rb/l42_my_ruby.svg)](http://badge.fury.io/rb/l42_my_ruby)
4
+ [![Gem Downloads](https://img.shields.io/gem/dt/l42_my_ruby.svg)](https://rubygems.org/gems/l42_my_ruby)
5
+
1
6
  # L42MyRuby
2
7
 
3
8
  Occupying the `L42` namespace this gem provides tools and binaries useful to me (lab42) and
data/bin/mv_to_random ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/l42'
5
+
6
+ L42::Monad.interact(L42::Interfaces::ToRandom)
7
+ # SPDX-License-Identifier: Apache-2.0
data/bin/mv_with_ts ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ require_relative '../lib/l42'
4
+
5
+ L42::Monad.functional_output(L42::Interfaces::WithTs, *ARGV)
6
+ # SPDX-License-Identifier: Apache-2.0
data/bin/tx_send ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/l42'
5
+
6
+ output =
7
+ L42::Monad
8
+ .functional_input(L42::Interfaces::TxSend, ARGV.first, use_params: ARGV.drop(1))
9
+ output&.each do |line|
10
+ system(line)
11
+ end
12
+ # SPDX-License-Identifier: Apache-2.0
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lab42/rgxargs'
4
+ require 'securerandom'
5
+ module L42
6
+ module Interfaces
7
+ module ToRandom
8
+ extend self
9
+
10
+ def call(files)
11
+ Lab42::Rgxargs.new.parse(ARGV) => [kwds, args, *]
12
+ [
13
+ :stdout,
14
+ files.map(&_random_file(args, kwds))
15
+ ]
16
+ end
17
+
18
+ private
19
+
20
+ def _random_file(_args, kwds)
21
+ ->file do
22
+ ext = File.extname(file)
23
+ name = SecureRandom.hex((kwds.hex || 10).to_i)
24
+ ["mv #{file.inspect} ", name, ext].join
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ # SPDX-License-Identifier: Apache-2.0
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lab42/rgxargs'
4
+ module L42
5
+ module Interfaces
6
+ module TxSend
7
+ extend self
8
+
9
+ def call(lines, dest)
10
+ [
11
+ :stdout,
12
+ [*lines.map(&_send_to(dest)), "tmux select-window -t #{dest}"]
13
+ ]
14
+ end
15
+
16
+ private
17
+
18
+ def _send_to(dest)
19
+ ->line do
20
+ %(tmux send-keys -t #{dest} '#{line}' C-m)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ # SPDX-License-Identifier: Apache-2.0
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module L42
4
+ module Interfaces
5
+ module WithTs
6
+ extend self
7
+ def call(file_name, dest_dir, *tags)
8
+ [
9
+ :stdout,
10
+ %(mv #{file_name.inspect} #{File.join(dest_dir, _make_tagged_name(file_name, tags)).inspect})
11
+ ]
12
+ end
13
+
14
+ private
15
+ def _make_tagged_name(file_name, tags)
16
+ [*tags.sort, Time.now.to_i.to_s(16)].join("-") + File.extname(file_name)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ # SPDX-License-Identifier: Apache-2.0
data/lib/l42/monad.rb ADDED
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module L42
4
+ module Monad
5
+ extend self
6
+
7
+ class ContractViolation < RuntimeError; end
8
+
9
+ def interact(interactor, *args, **kwds)
10
+ case interactor.($stdin.readlines(chomp: true), *args, **kwds)
11
+ in [:stdout, output]
12
+ $stdout.puts(output)
13
+ in [:stderr, output]
14
+ $stderr.puts(output)
15
+ in x
16
+ raise ContractViolation,
17
+ "an interactor needs to return a result of type `[:stderr|:stdout, anything]`, not #{x.inspect}"
18
+ end
19
+ end
20
+
21
+ def functional_output(transformer, *args)
22
+ case transformer.(*args)
23
+ in [:stdout, output]
24
+ $stdout.puts(output)
25
+ in [:stderr, output]
26
+ $stderr.puts(output)
27
+ in x
28
+ raise ContractViolation,
29
+ "a transformer needs to return a result of type `[:stderr|:stdout, anything]`, not #{x.inspect}"
30
+ end
31
+ end
32
+
33
+ def functional_input(transformer, *args, use_params: nil)
34
+ input =
35
+ use_params || $stdin.readlines(chomp: true)
36
+ case transformer.(input, *args)
37
+ in [:stdout, output]
38
+ output
39
+ in [:stderr, output]
40
+ $stderr.puts(output)
41
+ exit(-1)
42
+ in x
43
+ raise ContractViolation,
44
+ "a transformer needs to return a result of type `[:stderr|:stdout, anything]`, not #{x.inspect}"
45
+ end
46
+ end
47
+ end
48
+ end
49
+ # SPDX-License-Identifier: Apache-2.0
data/lib/l42/version.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module L42
4
4
  module Version
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.4'
6
6
  end
7
7
  end
8
8
  # SPDX-License-Identifier: Apache-2.0
metadata CHANGED
@@ -1,34 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: l42_my_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-21 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-08-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lab42_rgxargs
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.1
13
27
  description: |
14
28
  All my Ruby Code
15
29
 
16
30
  Binaries and libs which make Ruby awesome (for me)
17
31
  email: robert.dober@gmail.com
18
- executables: []
32
+ executables:
33
+ - mv_to_random
34
+ - mv_with_ts
35
+ - tx_send
19
36
  extensions: []
20
37
  extra_rdoc_files: []
21
38
  files:
22
39
  - LICENSE
23
40
  - README.md
41
+ - bin/mv_to_random
42
+ - bin/mv_with_ts
43
+ - bin/tx_send
24
44
  - lib/l42.rb
25
45
  - lib/l42/data_class.rb
46
+ - lib/l42/interfaces/to_random.rb
47
+ - lib/l42/interfaces/tx_send.rb
48
+ - lib/l42/interfaces/with_ts.rb
49
+ - lib/l42/monad.rb
26
50
  - lib/l42/version.rb
27
51
  homepage: https://github.com/robertdober/l42_my_ruby
28
52
  licenses:
29
53
  - Apache-2.0
30
54
  metadata: {}
31
- post_install_message:
55
+ post_install_message:
32
56
  rdoc_options: []
33
57
  require_paths:
34
58
  - lib
@@ -44,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
68
  version: '0'
45
69
  requirements: []
46
70
  rubygems_version: 3.3.7
47
- signing_key:
71
+ signing_key:
48
72
  specification_version: 4
49
73
  summary: All my Ruby Code
50
74
  test_files: []