lab42_console 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -1
- data/lib/function.rb +0 -0
- data/lib/lab42/console.rb +15 -2
- data/lib/lab42/console/fn.rb +21 -0
- data/lib/lab42/console/h.rb +36 -0
- data/lib/lab42/console/intrusive.rb +43 -0
- data/lib/lab42/console/kwd.rb +52 -0
- data/lib/lab42/console/shortcut.rb +9 -0
- data/lib/lab42/console/tools.rb +37 -0
- data/lib/lab42/console/tools/forward_to_new_instance.rb +14 -0
- data/lib/lab42/console/version.rb +1 -1
- data/lib/lab42/functor.rb +23 -0
- data/lib/lab42/lazy.rb +14 -0
- metadata +55 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 312fd0d573b01d95bf651f4af2335c0ed1068014
|
4
|
+
data.tar.gz: 6ea484f492e56b24c2f297660200f43e5203ff64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a6d0752d73178a2b321c9522de1114eb1a982aeb95e98e83cdb2d01345f13ca9cda7850f035beb3bfb47cc26ea06105b03604136ef175372195a0bafa05941d
|
7
|
+
data.tar.gz: 36ae200a0903040d74585ce9b2eb0e6879fb2403c58ecfe916a175299d65645cbab74348cbbf8eb9cf6df7960648cd93b212b8494b4d2880b8758780fe654007
|
data/README.md
CHANGED
@@ -1,4 +1,16 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
# Lab42Console
|
3
|
+
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/lab42_console.svg)](http://badge.fury.io/rb/lab42_console) [![Build Status](https://travis-ci.org/RobertDober/lab42_console.svg?branch=master)](https://travis-ci.org/RobertDober/lab42_console) [![Test Coverage](https://codeclimate.com/github/RobertDober/lab42_console/badges/coverage.svg)](https://codeclimate.com/github/RobertDober/lab42_console)
|
5
|
+
|
6
|
+
<!--
|
7
|
+
[![Code Climate](https://codeclimate.com/github/RobertDober/lab42_core/badges/gpa.svg)](https://codeclimate.com/github/RobertDober/lab42_core)
|
8
|
+
[![Issue Count](https://codeclimate.com/github/RobertDober/lab42_core/badges/issue_count.svg)](https://codeclimate.com/github/RobertDober/lab42_core)
|
9
|
+
-->
|
10
|
+
|
11
|
+
Intrusive Ruby Tools for the Console Only
|
12
|
+
|
13
|
+
## Usage
|
2
14
|
|
3
15
|
```ruby
|
4
16
|
require 'lab42/console'
|
data/lib/function.rb
ADDED
File without changes
|
data/lib/lab42/console.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
|
+
require_relative 'console/h'
|
2
|
+
require_relative 'console/intrusive'
|
3
|
+
require_relative 'console/fn'
|
4
|
+
require_relative 'console/kwd'
|
5
|
+
require_relative 'console/shortcut'
|
6
|
+
|
7
|
+
require_relative 'lazy'
|
8
|
+
|
1
9
|
module Lab42
|
2
|
-
class Console
|
3
|
-
|
10
|
+
class Console
|
11
|
+
def kwd; Kwd end
|
12
|
+
def h; H end
|
4
13
|
end
|
5
14
|
end
|
15
|
+
|
16
|
+
class Object
|
17
|
+
include Lab42::Console::Shortcut
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative './tools.rb'
|
2
|
+
module Lab42
|
3
|
+
class Console
|
4
|
+
module Fn
|
5
|
+
def fn desc, *args, &blk
|
6
|
+
case desc
|
7
|
+
when Symbol, String
|
8
|
+
Tools.make_fn [desc, *args], blk
|
9
|
+
else
|
10
|
+
raise ArgumentError, "#{desc} does not describe a function"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def p rcv, name, *args, &blk
|
15
|
+
m = rcv.method(name)
|
16
|
+
Tools.make_partial m, args, blk
|
17
|
+
end
|
18
|
+
end
|
19
|
+
include Fn
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'tools/forward_to_new_instance'
|
2
|
+
module Lab42
|
3
|
+
class Console
|
4
|
+
class H
|
5
|
+
extend Tools::ForwardToNewInstance
|
6
|
+
|
7
|
+
attr_reader :hash
|
8
|
+
|
9
|
+
def find *keys
|
10
|
+
prewalk hash
|
11
|
+
end
|
12
|
+
|
13
|
+
def pre_walk nodes, condition, visitor, visited: Set.new
|
14
|
+
return if visisted.includes? nodes
|
15
|
+
case nodes
|
16
|
+
when Hash
|
17
|
+
walk_hash_pairs nodes, condition, visitor, visited: visited
|
18
|
+
when Enumerable
|
19
|
+
nodes.each do |ele|
|
20
|
+
pre_walk ele, condition, visitor, visited: visited.add(ele)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def initialize hash
|
28
|
+
@hash = hash
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def walk_hash_pairs nodes, condition, visitor, visited:
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative './tools'
|
2
|
+
|
3
|
+
# This is the reason not to use this anywhere else but in the console!!!
|
4
|
+
# =======================================================================
|
5
|
+
|
6
|
+
class Object
|
7
|
+
def identity; self end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Enumerable
|
11
|
+
|
12
|
+
def f *args, &blk
|
13
|
+
blk = Lab42::Console::Tools.make_fn(args, blk)
|
14
|
+
Lab42::Lazy.new(self) do | yielder, element |
|
15
|
+
yielder << element if blk.(element)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def f! *args, &blk
|
20
|
+
blk = Lab42::Console::Tools.make_fn(args, blk)
|
21
|
+
Lab42::Lazy.new(self) do | yielder, element |
|
22
|
+
yielder << element unless blk.(element)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def m *args, &blk
|
27
|
+
blk = Lab42::Console::Tools.make_fn(args, blk)
|
28
|
+
Lab42::Lazy.new(self) do | yielder, element |
|
29
|
+
yielder << ( blk ? blk.(element) : element )
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def fm *args, &blk
|
34
|
+
blk = Lab42::Console::Tools.make_fn(args, blk)
|
35
|
+
Lab42::Lazy.new(self) do | yielder, element |
|
36
|
+
producer = Array(blk ? blk.(element) : element)
|
37
|
+
producer.lazy.each do |ele|
|
38
|
+
yielder << ele
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative 'tools/forward_to_new_instance'
|
2
|
+
|
3
|
+
module Lab42
|
4
|
+
class Console
|
5
|
+
class Kwd
|
6
|
+
extend Tools::ForwardToNewInstance
|
7
|
+
|
8
|
+
attr_reader :kwds
|
9
|
+
|
10
|
+
|
11
|
+
def count *keys
|
12
|
+
kwds.count{ |pairs| keys.include? pairs.keys.first }
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def first_value *keys
|
17
|
+
raise ArgumentError, "need 0, 1, got #{keys.size}" unless keys.size < 2
|
18
|
+
key = keys.first
|
19
|
+
if key
|
20
|
+
kwds.find{ |pairs| pairs.keys.first == key }.values.first
|
21
|
+
else
|
22
|
+
kwds.first.values.first
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def last_value *keys
|
27
|
+
raise ArgumentError, "need 0, 1, got #{keys.size}" unless keys.size < 2
|
28
|
+
key = keys.first
|
29
|
+
if key
|
30
|
+
kwds.reverse.find{ |pairs| pairs.keys.first == key }.values.first
|
31
|
+
else
|
32
|
+
kwds.reverse.first.values.first
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def values *keys
|
37
|
+
if keys.empty?
|
38
|
+
kwds.map{ |pairs| pairs.values.first }
|
39
|
+
else
|
40
|
+
kwds.map{ |pairs| keys.include?(pairs.keys.first) && pairs.values.first }.select(&:identity)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def initialize kwds
|
48
|
+
@kwds = kwds
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Lab42
|
2
|
+
class Console
|
3
|
+
module Tools extend self
|
4
|
+
|
5
|
+
|
6
|
+
def make_fn fn_ary, blk
|
7
|
+
|
8
|
+
return ->(x){x} if fn_ary.empty? && blk.nil?
|
9
|
+
return blk if fn_ary.empty?
|
10
|
+
|
11
|
+
make_fn_from_ary( *fn_ary ).tap do | argfn |
|
12
|
+
# Chain in one pass if applicable
|
13
|
+
return ->(x){ blk.(argfn.(x)) } if blk
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def make_fn_from_ary desc, *args
|
18
|
+
-> (rcv, *a) {
|
19
|
+
rcv.send(desc, *(args + a))
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def make_partial mthd, args, blk
|
25
|
+
make_partial_from(mthd, args).tap do | partial |
|
26
|
+
return ->(*x){ blk.(partial.(*x)) } if blk
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def make_partial_from mthd, args
|
31
|
+
-> (*a) {
|
32
|
+
mthd.( *(args + a) )
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Lab42
|
2
|
+
class Functor < BasicObject
|
3
|
+
|
4
|
+
attr_reader :function, :result
|
5
|
+
|
6
|
+
|
7
|
+
def call *args
|
8
|
+
@result = function.(*args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def inspect
|
12
|
+
result.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def initialize &function
|
18
|
+
@function = function
|
19
|
+
@result = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/lab42/lazy.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lab42_console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forwarder2
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: lab42_function
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: pry
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,34 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '3.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.15'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.15'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: codeclimate-test-reporter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.0'
|
69
111
|
- !ruby/object:Gem::Dependency
|
70
112
|
name: travis-lint
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,8 +131,18 @@ extra_rdoc_files: []
|
|
89
131
|
files:
|
90
132
|
- LICENSE
|
91
133
|
- README.md
|
134
|
+
- lib/function.rb
|
92
135
|
- lib/lab42/console.rb
|
136
|
+
- lib/lab42/console/fn.rb
|
137
|
+
- lib/lab42/console/h.rb
|
138
|
+
- lib/lab42/console/intrusive.rb
|
139
|
+
- lib/lab42/console/kwd.rb
|
140
|
+
- lib/lab42/console/shortcut.rb
|
141
|
+
- lib/lab42/console/tools.rb
|
142
|
+
- lib/lab42/console/tools/forward_to_new_instance.rb
|
93
143
|
- lib/lab42/console/version.rb
|
144
|
+
- lib/lab42/functor.rb
|
145
|
+
- lib/lab42/lazy.rb
|
94
146
|
homepage: https://github.com/RobertDober/lab42_console
|
95
147
|
licenses:
|
96
148
|
- Apache
|
@@ -112,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
164
|
version: '0'
|
113
165
|
requirements: []
|
114
166
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.6.
|
167
|
+
rubygems_version: 2.6.11
|
116
168
|
signing_key:
|
117
169
|
specification_version: 4
|
118
170
|
summary: Useful but Intrusive Ruby Tools for the console use only there!
|