lab42_core 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +14 -1
- data/lib/lab42/core/file.rb +23 -1
- data/lib/lab42/core/version.rb +1 -1
- data/lib/lab42/file.rb +14 -0
- data/lib/lab42/lazy.rb +8 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf5aec7a9918cd936728fb06721e663d530c901e
|
4
|
+
data.tar.gz: 08d0c079fd94050faea45f17e8d155d1d788e3b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ceabf66233750d990fed83eb335f7ac27b3646e01be7d45612df31b1b057cb219353eeb0f70d371c8161c291329467f086a1cfecf239eecddccb58282718f2b
|
7
|
+
data.tar.gz: 3d1596f2c2323bc904f80db7c249cc8e8b079ae6839ff9748c8f3b6879e12dc17a5e7a532bc4f90324c96dee7200299a6200a695ddd248383c19566fdb6bdec6
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
[](https://travis-ci.org/RobertDober/lab42_core)
|
8
8
|
[](https://codeclimate.com/github/RobertDober/lab42_core)
|
9
9
|
[](https://codeclimate.com/github/RobertDober/lab42_core)
|
10
|
-
|
10
|
+
[](http://badge.fury.io/rb/lab42_core)
|
11
11
|
|
12
12
|
Simple Ruby Core Module Extensions (for more see lab42\_more)
|
13
13
|
|
@@ -65,10 +65,23 @@ For details see the corresponding [QED demo](https://github.com/RobertDober/lab4
|
|
65
65
|
|
66
66
|
## File
|
67
67
|
|
68
|
+
### `expand_local_path`
|
69
|
+
|
68
70
|
`expand_local_path` to get rid of the `__FILE__` inside `expand_path`.
|
69
71
|
|
70
72
|
For details see the corresponding [QED demo](https://github.com/RobertDober/lab42_core/blob/master/demo/file.md).
|
71
73
|
|
74
|
+
### `if_readable`
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
File.if_readable 'some_file' do | file | # openes file as readable
|
78
|
+
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
|
83
|
+
### `if_writeable`
|
84
|
+
|
72
85
|
## Hash
|
73
86
|
|
74
87
|
```ruby
|
data/lib/lab42/core/file.rb
CHANGED
@@ -1,8 +1,30 @@
|
|
1
|
+
require_relative '../file'
|
2
|
+
|
1
3
|
class << File
|
2
4
|
def expand_local_path *args, &blk
|
3
5
|
raise ArgumentError, 'need a block to determine source location' unless blk
|
4
6
|
values = args + Array( blk.() )
|
5
7
|
expand_path File.join( '..', values.compact), blk.source_location.first
|
6
|
-
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def if_readable path, &blk
|
12
|
+
|
13
|
+
return Lab42::File.enumerate_on_file_readable path unless blk
|
14
|
+
|
15
|
+
return unless readable? path
|
16
|
+
return blk.() if blk.arity.zero?
|
17
|
+
|
18
|
+
File.open path, &blk
|
19
|
+
end
|
20
|
+
|
21
|
+
def if_writable path, &blk
|
22
|
+
|
23
|
+
return Lab42::File.enumerate_on_file_writable path unless blk
|
24
|
+
|
25
|
+
return unless writable? path
|
26
|
+
return blk.() if blk.arity.zero?
|
27
|
+
|
28
|
+
File.open path, "a", &blk
|
7
29
|
end
|
8
30
|
end # class << File
|
data/lib/lab42/core/version.rb
CHANGED
data/lib/lab42/file.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative 'lazy'
|
2
|
+
|
3
|
+
module Lab42
|
4
|
+
module File extend self
|
5
|
+
|
6
|
+
def enumerate_on_file_writable path
|
7
|
+
::File.writable?( path ) ? Lab42::Lazy.once( path ) : Lab42::Lazy::Never
|
8
|
+
end
|
9
|
+
|
10
|
+
def enumerate_on_file_readable path
|
11
|
+
::File.readable?( path ) ? Lab42::Lazy.once( path ) : Lab42::Lazy::Never
|
12
|
+
end
|
13
|
+
end # module File
|
14
|
+
end # module Lab42
|
data/lib/lab42/lazy.rb
ADDED
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.1.
|
4
|
+
version: 0.1.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: 2014-11-
|
11
|
+
date: 2014-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forwarder2
|
@@ -125,6 +125,8 @@ files:
|
|
125
125
|
- lib/lab42/core/hash.rb
|
126
126
|
- lib/lab42/core/open_object.rb
|
127
127
|
- lib/lab42/core/version.rb
|
128
|
+
- lib/lab42/file.rb
|
129
|
+
- lib/lab42/lazy.rb
|
128
130
|
homepage: https://github.com/RobertDober/lab42_core
|
129
131
|
licenses:
|
130
132
|
- MIT
|
@@ -145,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
147
|
version: '0'
|
146
148
|
requirements: []
|
147
149
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.
|
150
|
+
rubygems_version: 2.4.3
|
149
151
|
signing_key:
|
150
152
|
specification_version: 4
|
151
153
|
summary: Simple Ruby Core Module Extensions (for more see lab42_more)
|