lab42_core 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5abf33645e91cd25afc2561b6d8b16a2aa7f5cd8
4
- data.tar.gz: 09f7c35a4b526bbd577b549ff7a8b260168137e0
3
+ metadata.gz: cf5aec7a9918cd936728fb06721e663d530c901e
4
+ data.tar.gz: 08d0c079fd94050faea45f17e8d155d1d788e3b9
5
5
  SHA512:
6
- metadata.gz: a755bb762ce16516d920c1b48e8c7c2843dafa2acc08cc63400b89f8eaf960114190c996b4a60620dd22a44c99f6883620a831827667fb9d06e5bd113159c36c
7
- data.tar.gz: dc4ae82fb3c196b5fc7b8ff581db88d586af9bdfea529c57b2dce1a7eea844208a2174ee907d9d95c436248ddf96128143ad29ec0b370ba3b84b5cc0170df9c0
6
+ metadata.gz: 8ceabf66233750d990fed83eb335f7ac27b3646e01be7d45612df31b1b057cb219353eeb0f70d371c8161c291329467f086a1cfecf239eecddccb58282718f2b
7
+ data.tar.gz: 3d1596f2c2323bc904f80db7c249cc8e8b079ae6839ff9748c8f3b6879e12dc17a5e7a532bc4f90324c96dee7200299a6200a695ddd248383c19566fdb6bdec6
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Build Status](https://travis-ci.org/RobertDober/lab42_core.svg?branch=master)](https://travis-ci.org/RobertDober/lab42_core)
8
8
  [![Code Climate](https://codeclimate.com/github/RobertDober/lab42_core/badges/gpa.svg)](https://codeclimate.com/github/RobertDober/lab42_core)
9
9
  [![Test Coverage](https://codeclimate.com/github/RobertDober/lab42_core/badges/coverage.svg)](https://codeclimate.com/github/RobertDober/lab42_core)
10
-
10
+ [![Gem Version](https://badge.fury.io/rb/lab42_core.svg)](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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Lab42
2
2
  module Core
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end # module Core
5
5
  end # module Lab42
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
@@ -0,0 +1,8 @@
1
+ module Lab42
2
+ module Lazy extend self
3
+ Never = Enumerator.new{}
4
+ def once value
5
+ Enumerator.new{ |y| y << value }
6
+ end
7
+ end # module Lazy
8
+ end # module Lab42
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.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-23 00:00:00.000000000 Z
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.2.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)