io-like 0.3.0 → 0.3.1
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.
- data/.yardopts +1 -0
- data/LICENSE +22 -57
- data/{LICENSE.rubyspec → LICENSE-rubyspec} +0 -0
- data/{NEWS → NEWS.md} +10 -5
- data/README.md +269 -0
- data/Rakefile +228 -0
- data/ruby.1.8.mspec +7 -0
- data/spec/binmode_spec.rb +29 -0
- data/spec/close_read_spec.rb +64 -0
- data/spec/close_spec.rb +36 -0
- data/spec/close_write_spec.rb +61 -0
- data/spec/closed_spec.rb +16 -0
- data/spec/each_byte_spec.rb +38 -0
- data/spec/each_line_spec.rb +11 -0
- data/spec/each_spec.rb +11 -0
- data/spec/eof_spec.rb +11 -0
- data/spec/fixtures/classes.rb +96 -0
- data/spec/fixtures/gets.txt +9 -0
- data/spec/fixtures/numbered_lines.txt +5 -0
- data/spec/fixtures/one_byte.txt +1 -0
- data/spec/fixtures/paragraphs.txt +7 -0
- data/spec/fixtures/readlines.txt +6 -0
- data/spec/flush_spec.rb +8 -0
- data/spec/getc_spec.rb +44 -0
- data/spec/gets_spec.rb +212 -0
- data/spec/isatty_spec.rb +6 -0
- data/spec/lineno_spec.rb +84 -0
- data/spec/output_spec.rb +47 -0
- data/spec/pos_spec.rb +53 -0
- data/spec/print_spec.rb +97 -0
- data/spec/printf_spec.rb +24 -0
- data/spec/putc_spec.rb +57 -0
- data/spec/puts_spec.rb +99 -0
- data/spec/read_spec.rb +162 -0
- data/spec/readchar_spec.rb +49 -0
- data/spec/readline_spec.rb +60 -0
- data/spec/readlines_spec.rb +140 -0
- data/spec/readpartial_spec.rb +92 -0
- data/spec/rewind_spec.rb +56 -0
- data/spec/seek_spec.rb +72 -0
- data/spec/shared/each.rb +204 -0
- data/spec/shared/eof.rb +116 -0
- data/spec/shared/pos.rb +39 -0
- data/spec/shared/tty.rb +12 -0
- data/spec/shared/write.rb +53 -0
- data/spec/sync_spec.rb +56 -0
- data/spec/sysread_spec.rb +87 -0
- data/spec/sysseek_spec.rb +68 -0
- data/spec/syswrite_spec.rb +60 -0
- data/spec/tell_spec.rb +7 -0
- data/spec/to_io_spec.rb +19 -0
- data/spec/tty_spec.rb +6 -0
- data/spec/ungetc_spec.rb +118 -0
- data/spec/write_spec.rb +61 -0
- data/spec_helper.rb +49 -0
- metadata +223 -32
- data/CONTRIBUTORS +0 -15
- data/GPL +0 -676
- data/HACKING +0 -123
- data/LEGAL +0 -56
- data/MANIFEST +0 -10
- data/README +0 -150
data/HACKING
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
= Guide to Hacking IO::Like
|
2
|
-
|
3
|
-
== Licensing
|
4
|
-
|
5
|
-
Contributed code must be licensed under the same license as this project. See
|
6
|
-
the included LICENSE file for details. Special consideration MAY be made in
|
7
|
-
some cases, but such cases will be rare.
|
8
|
-
|
9
|
-
|
10
|
-
== Dependencies
|
11
|
-
|
12
|
-
=== Runtime
|
13
|
-
|
14
|
-
* Ruby 1.8.6 or greater
|
15
|
-
|
16
|
-
|
17
|
-
=== Build
|
18
|
-
|
19
|
-
* rubygems 0.9.0 or greater
|
20
|
-
* rake 0.8.3 or greater
|
21
|
-
* mspec 1.5.9 (optional - used for testing)
|
22
|
-
* allison 2.0.3 (optional - used for documentation only, if available)
|
23
|
-
* rsync (optional - used for publishing documentation)
|
24
|
-
|
25
|
-
|
26
|
-
=== Install
|
27
|
-
|
28
|
-
* rubygems 0.9.0 or greater
|
29
|
-
|
30
|
-
|
31
|
-
== Versioning Policy
|
32
|
-
|
33
|
-
Version numbers will be in <em>x.y.z</em> format, where <em>x</em>, <em>y</em>,
|
34
|
-
and <em>z</em> are integers starting from 0. The version increment rules are
|
35
|
-
as follows:
|
36
|
-
|
37
|
-
<b>x</b>:: Planned releases which implement significant changes and/or break API
|
38
|
-
compatibility. An exception is to be made for the transition from
|
39
|
-
the <em>0.y.z</em> series to the <em>1.y.z</em> series since the
|
40
|
-
<em>0.y.z</em> series is expected to be unstable throughout
|
41
|
-
development. When incremented, <em>y</em> and <em>z</em> are reset
|
42
|
-
to 0.
|
43
|
-
<b>y</b>:: Planned releases which incorporate numerous bug fixes and/or new
|
44
|
-
features which do not break backward compatibility. When
|
45
|
-
incremented, <em>z</em> is reset to 0.
|
46
|
-
<b>z</b>:: Generally, unplanned releases which incorporate a single fix for a
|
47
|
-
critical defect.
|
48
|
-
|
49
|
-
This is the {Rational Versioning Policy}[http://www.rubygems.org/read/chapter/7]
|
50
|
-
as outlined in the {RubyGems User Guide}[http://www.rubygems.org/read/book/1].
|
51
|
-
|
52
|
-
|
53
|
-
== Support Policy
|
54
|
-
|
55
|
-
Due to limitations in resources (time/money/manpower), this project will focus
|
56
|
-
primarily upon the development line of the current release at any given time.
|
57
|
-
Fixes and new features should be applied first to that development line and then
|
58
|
-
backported to earlier releases if necessary and feasible. Long term maintenance
|
59
|
-
of previous releases is not planned. Users are generally expected to upgrade to
|
60
|
-
the latest release in order to receive updates unless an explicit declaration of
|
61
|
-
support for a previous release is made.
|
62
|
-
|
63
|
-
|
64
|
-
== Coding Style
|
65
|
-
|
66
|
-
The following points are not necessarily set in stone but should rather be used
|
67
|
-
as a good guideline. Consistency is the goal of coding style, and changes will
|
68
|
-
be more easily accepted if they are consistent with the rest of the code.
|
69
|
-
|
70
|
-
<b>File Encoding</b>:: UTF-8
|
71
|
-
<b>Indentation</b>:: Two spaces; no tabs
|
72
|
-
<b>Comments</b>:: Document classes, attributes, methods, and code
|
73
|
-
<b>Boolean Operators</b>:: Use <tt>&&</tt> and <tt>||</tt> for boolean tests;
|
74
|
-
avoid <tt>and</tt> and <tt>or</tt>
|
75
|
-
<b>Method Calls</b>:: Use <tt>a_method(arg, arg, etc)</tt>; <b>not</b>
|
76
|
-
<tt>a_method( arg, arg, etc )</tt>,
|
77
|
-
<tt>a_method arg, arg, etc</tt>, or any other
|
78
|
-
variation
|
79
|
-
<b>Blocks</b>:: <tt>do end</tt> for multi-line blocks and
|
80
|
-
<tt>{ }</tt> for single-line blocks
|
81
|
-
<b>Line length</b>:: Limit lines to a maximum of 80 characters
|
82
|
-
<b>General</b>:: Try to follow the flow and style of the rest of the
|
83
|
-
code
|
84
|
-
|
85
|
-
|
86
|
-
== Generating Patches
|
87
|
-
|
88
|
-
Patches should usually be generated against the <em>HEAD</em> revision of the
|
89
|
-
<em>master</em> branch. When generating patches, please try to implement only
|
90
|
-
a single feature or bug fix per patch. Documentation describing a patch should
|
91
|
-
be included along with the patch so that the maintainer can more easily
|
92
|
-
determine whether or not a patch is acceptable. Patches lacking the necessary
|
93
|
-
documentation will be ignored.
|
94
|
-
|
95
|
-
Patches will be much more readily accepted if test cases are provided which
|
96
|
-
verify correct operation. Such test cases should be provided within the patch
|
97
|
-
rather than as a separate patch. Proper documentation, especially for
|
98
|
-
user-visible APIs, is highly prized; providing accurate and detailed
|
99
|
-
documentation, often in the form of rubydocs, throughout new code contributions
|
100
|
-
will also increase the desirability of a patch.
|
101
|
-
|
102
|
-
If a series of patches is generated which cannot be applied individually, make
|
103
|
-
sure to mention the dependency relationships in whatever medium is being used
|
104
|
-
to distribute the patches. For instance, if a bug is discovered while
|
105
|
-
implementing a new feature, create a patch which fixes the bug followed by a
|
106
|
-
separate patch adding the feature. If the feature patch requires the bug fix
|
107
|
-
patch in order to work, note that dependency in the comments for the feature
|
108
|
-
patch by somehow referencing the bug fix patch.
|
109
|
-
|
110
|
-
The patch generation process in general:
|
111
|
-
$ git clone git://rubyforge.org/io-like.git # Clone the repo and check out
|
112
|
-
# the master branch.
|
113
|
-
$ cd io-like # Enter the workspace.
|
114
|
-
(make and test changes)
|
115
|
-
$ git add file1 file2 .. # Add new/modified files.
|
116
|
-
$ git commit # Commit changes.
|
117
|
-
$ git format-patch -C HEAD^ # Create a patch for the last
|
118
|
-
# commit.
|
119
|
-
|
120
|
-
Repeat as necessary until all patches are generated. Then either attach them to
|
121
|
-
1 or more email messages addressed to the maintainer or attach them to tickets
|
122
|
-
in the issue tracker for the project. Remember to include a brief description
|
123
|
-
of the patch and its dependencies, if any.
|
data/LEGAL
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
= Other Legalities
|
2
|
-
|
3
|
-
== Files Licensed Differently
|
4
|
-
|
5
|
-
The following file(s) are provided under a license or licenses separate from
|
6
|
-
this project.
|
7
|
-
|
8
|
-
See LICENSE.rubyspec for terms of use for the following:
|
9
|
-
spec/binmode_spec.rb
|
10
|
-
spec/close_read_spec.rb
|
11
|
-
spec/close_spec.rb
|
12
|
-
spec/close_write_spec.rb
|
13
|
-
spec/closed_spec.rb
|
14
|
-
spec/each_byte_spec.rb
|
15
|
-
spec/each_line_spec.rb
|
16
|
-
spec/each_spec.rb
|
17
|
-
spec/eof_spec.rb
|
18
|
-
spec/fixtures/classes.rb
|
19
|
-
spec/fixtures/gets.txt
|
20
|
-
spec/fixtures/numbered_lines.txt
|
21
|
-
spec/fixtures/one_byte.txt
|
22
|
-
spec/fixtures/paragraphs.txt
|
23
|
-
spec/fixtures/readlines.txt
|
24
|
-
spec/flush_spec.rb
|
25
|
-
spec/getc_spec.rb
|
26
|
-
spec/gets_spec.rb
|
27
|
-
spec/isatty_spec.rb
|
28
|
-
spec/lineno_spec.rb
|
29
|
-
spec/output_spec.rb
|
30
|
-
spec/pos_spec.rb
|
31
|
-
spec/print_spec.rb
|
32
|
-
spec/printf_spec.rb
|
33
|
-
spec/putc_spec.rb
|
34
|
-
spec/puts_spec.rb
|
35
|
-
spec/read_spec.rb
|
36
|
-
spec/readchar_spec.rb
|
37
|
-
spec/readline_spec.rb
|
38
|
-
spec/readlines_spec.rb
|
39
|
-
spec/readpartial_spec.rb
|
40
|
-
spec/rewind_spec.rb
|
41
|
-
spec/seek_spec.rb
|
42
|
-
spec/shared/each.rb
|
43
|
-
spec/shared/eof.rb
|
44
|
-
spec/shared/pos.rb
|
45
|
-
spec/shared/tty.rb
|
46
|
-
spec/shared/write.rb
|
47
|
-
spec/sync_spec.rb
|
48
|
-
spec/sysread_spec.rb
|
49
|
-
spec/sysseek_spec.rb
|
50
|
-
spec/syswrite_spec.rb
|
51
|
-
spec/tell_spec.rb
|
52
|
-
spec/to_io_spec.rb
|
53
|
-
spec/tty_spec.rb
|
54
|
-
spec/ungetc_spec.rb
|
55
|
-
spec/write_spec.rb
|
56
|
-
spec_helper.rb
|
data/MANIFEST
DELETED
data/README
DELETED
@@ -1,150 +0,0 @@
|
|
1
|
-
= IO::Like - in the Likeness of IO
|
2
|
-
|
3
|
-
The IO::Like module provides all of the methods of typical IO implementations
|
4
|
-
such as File; most importantly the read, write, and seek series of methods. A
|
5
|
-
class which includes IO::Like needs to provide only a few methods in order to
|
6
|
-
enable the higher level methods. Buffering is automatically provided by default
|
7
|
-
for the methods which normally provide it in IO.
|
8
|
-
|
9
|
-
See the documentation for IO::Like for more details regarding the necessary
|
10
|
-
methods.
|
11
|
-
|
12
|
-
|
13
|
-
== License
|
14
|
-
|
15
|
-
Copyright © 2008,2009 Jeremy Bopp <jeremy at bopp dot net>
|
16
|
-
|
17
|
-
Licensed under the same terms as Ruby -- See the included LICENSE file for
|
18
|
-
details
|
19
|
-
|
20
|
-
Some parts licensed under the same terms as the rubyspec project -- See the
|
21
|
-
included LEGAL and LICENSE.rubyspec files for details
|
22
|
-
|
23
|
-
|
24
|
-
== Installation/Removal
|
25
|
-
|
26
|
-
Download the GEM file and install it with:
|
27
|
-
% sudo gem install io-like-VERSION.gem
|
28
|
-
|
29
|
-
or directly with:
|
30
|
-
% sudo gem install io-like
|
31
|
-
|
32
|
-
Removal is the same in either case:
|
33
|
-
% sudo gem uninstall io-like
|
34
|
-
|
35
|
-
|
36
|
-
== Example
|
37
|
-
More examples can be found in the +examples+ directory of the source
|
38
|
-
distribution.
|
39
|
-
|
40
|
-
A simple ROT13 codec:
|
41
|
-
gem 'io-like' # Use require_gem for rubygems versions older than 0.9.0.
|
42
|
-
require 'io/like'
|
43
|
-
|
44
|
-
class ROT13Filter
|
45
|
-
include IO::Like
|
46
|
-
|
47
|
-
def self.open(delegate_io)
|
48
|
-
filter = new(delegate_io)
|
49
|
-
return filter unless block_given?
|
50
|
-
|
51
|
-
begin
|
52
|
-
yield(filter)
|
53
|
-
ensure
|
54
|
-
filter.close unless filter.closed?
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def initialize(delegate_io)
|
59
|
-
@delegate_io = delegate_io
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def encode_rot13(string)
|
65
|
-
result = string.dup
|
66
|
-
0.upto(result.length) do |i|
|
67
|
-
case result[i]
|
68
|
-
when 65..90
|
69
|
-
result[i] = (result[i] - 52) % 26 + 65
|
70
|
-
when 97..122
|
71
|
-
result[i] = (result[i] - 84) % 26 + 97
|
72
|
-
end
|
73
|
-
end
|
74
|
-
result
|
75
|
-
end
|
76
|
-
|
77
|
-
def unbuffered_read(length)
|
78
|
-
encode_rot13(@delegate_io.sysread(length))
|
79
|
-
end
|
80
|
-
|
81
|
-
def unbuffered_seek(offset, whence = IO::SEEK_SET)
|
82
|
-
@delegate_io.sysseek(offset, whence)
|
83
|
-
end
|
84
|
-
|
85
|
-
def unbuffered_write(string)
|
86
|
-
@delegate_io.syswrite(encode_rot13(string))
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
File.open('normal_file.txt', 'w') do |f|
|
91
|
-
f.puts('This is a test')
|
92
|
-
end
|
93
|
-
|
94
|
-
File.open('rot13_file.txt', 'w') do |f|
|
95
|
-
ROT13Filter.open(f) do |rot13|
|
96
|
-
rot13.puts('This is a test')
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
File.open('normal_file.txt') do |f|
|
101
|
-
ROT13Filter.open(f) do |rot13|
|
102
|
-
puts(rot13.read) # -> Guvf vf n grfg
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
File.open('rot13_file.txt') do |f|
|
107
|
-
ROT13Filter.open(f) do |rot13|
|
108
|
-
puts(rot13.read) # -> This is a test
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
File.open('normal_file.txt') do |f|
|
113
|
-
ROT13Filter.open(f) do |rot13|
|
114
|
-
rot13.pos = 5
|
115
|
-
puts(rot13.read) # -> vf n grfg
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
File.open('rot13_file.txt') do |f|
|
120
|
-
ROT13Filter.open(f) do |rot13|
|
121
|
-
rot13.pos = 5
|
122
|
-
puts(rot13.read) # -> is a test
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
File.open('normal_file.txt') do |f|
|
127
|
-
ROT13Filter.open(f) do |rot13|
|
128
|
-
ROT13Filter.open(rot13) do |rot26| # ;-)
|
129
|
-
puts(rot26.read) # -> This is a test
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
|
135
|
-
== Known Bugs/Limitations
|
136
|
-
|
137
|
-
1. Only up to version 1.8.6 of Ruby's IO interface is implemented. Version
|
138
|
-
1.8.7 and eventually 1.9.0/2.0.0 support are coming soon.
|
139
|
-
2. Ruby's finalization capabilities fall a bit short in a few respects, and as a
|
140
|
-
result, it is impossible to cause the close, close_read, or close_write
|
141
|
-
methods to be called automatically when an including class is garbage
|
142
|
-
collected. Define a class open method in the manner of File.open which
|
143
|
-
guarantees that an appropriate close method will be called after executing a
|
144
|
-
block. Other than that, be diligent about calling the close methods.
|
145
|
-
|
146
|
-
|
147
|
-
== Contributing
|
148
|
-
|
149
|
-
Contributions for bug fixes, documentation, extensions, tests, etc. are
|
150
|
-
encouraged. Please read the file HACKING for details.
|