lab42_core 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +60 -48
- data/lib/lab42/core/console_tools/enumerable.rb +6 -0
- data/lib/lab42/core/console_tools/func.rb +33 -0
- data/lib/lab42/core/console_tools.rb +9 -0
- data/lib/lab42/core/kernel.rb +0 -0
- data/lib/lab42/core/memoization.rb +5 -0
- data/lib/lab42/core/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f7dde044401dfbe2f779d84728f458dd3c49370
|
4
|
+
data.tar.gz: 14507f78a4d194afb9b243f83b0bf1913dce1e3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 015ae1a78dc4bd449030db2be0bb75535038688f3785d5e1ae33ed7893d795263219ea097f30e5e0e15a269f17fd639e1f327ab70a430ddfc5d0d6dbda1a8f56
|
7
|
+
data.tar.gz: e2bb5e9166067edd5ea90009f4568788650ca1ce46a60515ea79b5e4c870fd2e10bb08229df1ef75e7a307e74e9e6d209e16e4edcb900c4cac361bb1c4b15332
|
data/README.md
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
# lab42\_core
|
4
2
|
|
5
3
|
|
@@ -12,9 +10,37 @@ Simple Ruby Core Module Extensions (for more see lab42\_more)
|
|
12
10
|
|
13
11
|
## Programming Paradigms
|
14
12
|
|
15
|
-
###
|
13
|
+
### Fn - Functional Access To Methods
|
14
|
+
|
15
|
+
Can be used after `require 'lab42/core/fn'` **only**.
|
16
|
+
|
17
|
+
Might be moved into gem [lab42\_more](https://github.com/RobertDober/lab42_more) in the future .
|
18
|
+
|
19
|
+
API will remain the same, require will change to `require 'lab42_more/fn'`
|
16
20
|
|
17
|
-
|
21
|
+
### fn like function
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Dir.files [APP_ROOT, 'spec', 'support', '**', '*.rb'], Kernel.fn.require
|
25
|
+
|
26
|
+
Dir.files( %w{.. assets ** *.txt} ).sort_by &File.fn.mtime
|
27
|
+
```
|
28
|
+
|
29
|
+
#### fm like function/method
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
%w{ alpha beta gamma delta }.sort_by &String.fm.size
|
33
|
+
```
|
34
|
+
|
35
|
+
**N.B.** This only works because the object behind the scenes of `Class#fm` knows how to bind
|
36
|
+
upon call, once it has been transformed by `#to_proc`
|
37
|
+
|
38
|
+
|
39
|
+
For details see the corresponding [QED demo](https://github.com/RobertDober/lab42_core/blob/master/demo/fn.md).
|
40
|
+
|
41
|
+
#### Memoization and Lazy Attributes
|
42
|
+
|
43
|
+
##### Memoization
|
18
44
|
|
19
45
|
is a, slightly forgotten, programming technique protecting against double calcultions.
|
20
46
|
|
@@ -82,7 +108,7 @@ two different syntaxes
|
|
82
108
|
|
83
109
|
```
|
84
110
|
|
85
|
-
|
111
|
+
##### Lazy Attributes
|
86
112
|
|
87
113
|
Are just parameterless memoized methods, excatly the same as `let` bindings in [RSpec](http://www.rubydoc.info/gems/rspec-core/RSpec/Core/MemoizedHelpers/ClassMethods#let-instance_method).
|
88
114
|
|
@@ -103,7 +129,7 @@ the example above. They are by nature static while methods like the shortest pat
|
|
103
129
|
|
104
130
|
For details see the corresponding [QED demo](https://github.com/RobertDober/lab42_core/blob/master/demo/memoization.md).
|
105
131
|
|
106
|
-
|
132
|
+
##### Gotchas
|
107
133
|
|
108
134
|
Do not, I repeat, **Do not** memoize methods with side effects!
|
109
135
|
|
@@ -111,11 +137,13 @@ The exception is _cached reading_ as in the example above.
|
|
111
137
|
|
112
138
|
Do not call memoized methods with arguments that cannot be used as Hash keys like e.g. BasicObject instances or other objects not responding to the **original** `hash` method.
|
113
139
|
|
114
|
-
##
|
140
|
+
## Core Extensions
|
141
|
+
|
142
|
+
### Array
|
115
143
|
|
116
144
|
Can be used after `require 'lab42/core'` or `require 'lab42/core/array'`
|
117
145
|
|
118
|
-
|
146
|
+
#### #flatten\_once
|
119
147
|
|
120
148
|
```ruby
|
121
149
|
[].flatten_once.assert.empty?
|
@@ -126,7 +154,7 @@ Can be used after `require 'lab42/core'` or `require 'lab42/core/array'`
|
|
126
154
|
|
127
155
|
For details see the corresponding [QED demo](https://github.com/RobertDober/lab42_core/blob/master/demo/array.md).
|
128
156
|
|
129
|
-
|
157
|
+
### Dir
|
130
158
|
|
131
159
|
Can be used after `require 'lab42/core'` or `require 'lab42/core/dir'`
|
132
160
|
|
@@ -144,16 +172,16 @@ If only the relative or absolute pathes are needed there are the two variations
|
|
144
172
|
|
145
173
|
For details see the corresponding [QED demo](https://github.com/RobertDober/lab42_core/blob/master/demo/dir.md).
|
146
174
|
|
147
|
-
|
175
|
+
### Enumerable
|
148
176
|
|
149
|
-
|
177
|
+
#### grep2
|
150
178
|
|
151
179
|
```ruby
|
152
180
|
enum.grep2 expr # ===>
|
153
181
|
enum.partition{ |ele| expr === ele }
|
154
182
|
```
|
155
183
|
|
156
|
-
|
184
|
+
#### to\_proc
|
157
185
|
|
158
186
|
And also `Enumerable#to\_proc` as e.g.
|
159
187
|
|
@@ -170,15 +198,15 @@ And also `Enumerable#to\_proc` as e.g.
|
|
170
198
|
|
171
199
|
For details see the corresponding [QED demo](https://github.com/RobertDober/lab42_core/blob/master/demo/enumerable.md).
|
172
200
|
|
173
|
-
|
201
|
+
### File
|
174
202
|
|
175
|
-
|
203
|
+
#### #expand_local_path
|
176
204
|
|
177
205
|
`expand_local_path` to get rid of the `__FILE__` inside `expand_path`.
|
178
206
|
|
179
207
|
For details see the corresponding [QED demo](https://github.com/RobertDober/lab42_core/blob/master/demo/file.md).
|
180
208
|
|
181
|
-
|
209
|
+
#### #if_readable
|
182
210
|
|
183
211
|
```ruby
|
184
212
|
File.if_readable 'some_file' do | file | # openes file as readable
|
@@ -187,17 +215,17 @@ For details see the corresponding [QED demo](https://github.com/RobertDober/lab4
|
|
187
215
|
```
|
188
216
|
|
189
217
|
|
190
|
-
|
218
|
+
#### #if_writeable
|
191
219
|
|
192
|
-
|
220
|
+
### Hash
|
193
221
|
|
194
|
-
|
222
|
+
#### #only
|
195
223
|
|
196
224
|
```ruby
|
197
225
|
{a: 42, b: 43}.only :a, :c # ===> {a: 42}
|
198
226
|
```
|
199
227
|
|
200
|
-
|
228
|
+
#### #fetch! (read fetch and set)
|
201
229
|
|
202
230
|
```ruby
|
203
231
|
a = {a: 42}
|
@@ -210,39 +238,12 @@ are provided (after all there is a !).
|
|
210
238
|
|
211
239
|
For details see the corresponding [QED demo](https://github.com/RobertDober/lab42_core/blob/master/demo/hash.md).
|
212
240
|
|
213
|
-
## Fn
|
214
|
-
|
215
|
-
Can be used after `require 'lab42/core/array'` **only**.
|
216
241
|
|
217
|
-
|
218
|
-
|
219
|
-
API will remain the same, require will change to `require 'lab42_more/fn'`
|
220
|
-
|
221
|
-
### fn like function
|
222
|
-
|
223
|
-
```ruby
|
224
|
-
Dir.files [APP_ROOT, 'spec', 'support', '**', '*.rb'], Kernel.fn.require
|
225
|
-
|
226
|
-
Dir.files( %w{.. assets ** *.txt} ).sort_by &File.fn.mtime
|
227
|
-
```
|
228
|
-
|
229
|
-
### fm like function/method
|
230
|
-
|
231
|
-
```ruby
|
232
|
-
%w{ alpha beta gamma delta }.sort_by &String.fm.size
|
233
|
-
```
|
234
|
-
|
235
|
-
**N.B.** This only works because the object behind the scenes of `Class#fm` knows how to bind
|
236
|
-
upon call, once it has been transformed by `#to_proc`
|
237
|
-
|
238
|
-
|
239
|
-
For details see the corresponding [QED demo](https://github.com/RobertDober/lab42_core/blob/master/demo/fn.md).
|
240
|
-
|
241
|
-
## Object
|
242
|
+
### Object
|
242
243
|
|
243
244
|
Backport of `#itself` for versions < 2.2
|
244
245
|
|
245
|
-
|
246
|
+
### OpenObject
|
246
247
|
|
247
248
|
Immutable Open Objects
|
248
249
|
|
@@ -266,3 +267,14 @@ All _modifications_ just return a new instance.
|
|
266
267
|
```
|
267
268
|
|
268
269
|
For details see the corresponding [QED demo](https://github.com/RobertDober/lab42_core/blob/master/demo/open_object.md).
|
270
|
+
|
271
|
+
## Tools
|
272
|
+
|
273
|
+
### Console Tools
|
274
|
+
|
275
|
+
|
276
|
+
Can be used **only** after 'lab42/core/console_tools'.`
|
277
|
+
|
278
|
+
**N.B.** Never use in production code or applications. This code is extremly oriented console monkeypatching core classes massively.
|
279
|
+
|
280
|
+
This part is documented in [QED Console Tools](https://github.com/RobertDober/lab42_core/blob/master/demo/console_tools.md).
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
module Lab42
|
3
|
+
Receiver = BasicObject.new
|
4
|
+
end # module Lab42
|
5
|
+
|
6
|
+
def _realize_args_ para, args
|
7
|
+
args.map{ |arg| Proc === arg ? arg.(para) :arg }
|
8
|
+
end
|
9
|
+
|
10
|
+
def _transform_for_f_ args
|
11
|
+
args.map do | arg |
|
12
|
+
case arg
|
13
|
+
when Array
|
14
|
+
f *arg
|
15
|
+
else
|
16
|
+
arg
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def f *args
|
22
|
+
args = _transform_for_f_ args
|
23
|
+
# At this level we need to see if there is a Lab42::Receiver
|
24
|
+
if Symbol === args.first
|
25
|
+
-> r do
|
26
|
+
r.send *_realize_args_( r, args )
|
27
|
+
end
|
28
|
+
else
|
29
|
+
-> *r do
|
30
|
+
args.first.send *_realize_args_( r.first, args.drop(1) )
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
File without changes
|
data/lib/lab42/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lab42_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forwarder2
|
@@ -121,11 +121,15 @@ files:
|
|
121
121
|
- lib/lab42/core/array.rb
|
122
122
|
- lib/lab42/core/behavior.rb
|
123
123
|
- lib/lab42/core/behavior/proxy.rb
|
124
|
+
- lib/lab42/core/console_tools.rb
|
125
|
+
- lib/lab42/core/console_tools/enumerable.rb
|
126
|
+
- lib/lab42/core/console_tools/func.rb
|
124
127
|
- lib/lab42/core/dir.rb
|
125
128
|
- lib/lab42/core/enumerable.rb
|
126
129
|
- lib/lab42/core/file.rb
|
127
130
|
- lib/lab42/core/fn.rb
|
128
131
|
- lib/lab42/core/hash.rb
|
132
|
+
- lib/lab42/core/kernel.rb
|
129
133
|
- lib/lab42/core/memoization.rb
|
130
134
|
- lib/lab42/core/meta.rb
|
131
135
|
- lib/lab42/core/old_ruby2.rb
|