packable 1.3.13 → 1.3.14

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
  SHA256:
3
- metadata.gz: b1bd805026140ccad5845e20b2ff64e243e2f8884fdb3cb640d98d7e8019e0a5
4
- data.tar.gz: cfa942ab0edee1ea3e527672dfc5a4a378a575b583995df1867afa2693c524d3
3
+ metadata.gz: 010ee6e2262aa7ea8e3bccde2fa58a80afd1ba4356678c0456a638091cc50f97
4
+ data.tar.gz: 357c44f3a0252815976df5c4ac2260dabe87fb4d907546d1d8380fb37f714ae5
5
5
  SHA512:
6
- metadata.gz: 4b3252d9dc47e15c925a33551f6e5fca3b146ebb8a872310e3e0e10c9172695da7f31eae7e605ef048079dba1485ff55bc9b20a28868f710ee2be4f732e3c8c4
7
- data.tar.gz: 12fc57813c4d17964bd9ee74a9a61bdcf6fcdeab1bf7761e4695af184b15241093a0a1632a12b1801fcd4cb247814de18c0e8700117115aa18d64dc253a14dd0
6
+ metadata.gz: 34a8168ef33d77d73dfd27156db34a95e0787900611d5c88878c07953239d80a5e4ec57002057f044ca2fcfa3879295de67206f50e730395c264f84d0cbdcacd
7
+ data.tar.gz: 8619bf57c88279a4d5a852b6a3a7810495881665da8e160ffb7bbcd7b3fc7920e18ade6f50641d19ae341be5fd65447608f06260bc9f7543231a6e7f336d9289
@@ -1,5 +1,7 @@
1
1
  = Packable Library - Intro
2
2
 
3
+ *NOTE:* This library monkeypatches core classes and wa designed for Ruby 1.8 & 1.9. A redesign using refinements would be much better. Minimal support is provided.
4
+
3
5
  If you need to do read and write binary data, there is of course <tt>Array::pack</tt> and <tt>String::unpack</tt>.
4
6
  The packable library makes (un)packing nicer, smarter and more powerful.
5
7
  In case you are wondering why on earth someone would want to do serious (un)packing when YAML & XML are built-in:
@@ -10,6 +10,25 @@ module Packable
10
10
  base.alias_method_chain :each, :packing
11
11
  end
12
12
 
13
+ # Methods supported by seekable streams.
14
+ SEEKABLE_API = %i[pos pos= seek rewind].freeze
15
+
16
+ # Check whether can seek without errors.
17
+ def seekable?
18
+ if !defined?(@seekable)
19
+ @seekable =
20
+ # The IO class throws an exception at runtime if we try to change
21
+ # position on a non-regular file.
22
+ if respond_to?(:stat)
23
+ stat.file?
24
+ else
25
+ # Duck-type the rest of this.
26
+ SEEKABLE_API.all? { |m| respond_to?(m) }
27
+ end
28
+ end
29
+ @seekable
30
+ end
31
+
13
32
  # Returns the change in io.pos caused by the block.
14
33
  # Has nothing to do with packing, but quite helpful and so simple...
15
34
  def pos_change(&block)
@@ -53,17 +72,17 @@ module Packable
53
72
  end
54
73
 
55
74
  def each_with_packing(*options, &block)
56
- return each_without_packing(*options, &block) if options.empty? || (Integer === options.first) || (String === options.first) || tty?
75
+ return each_without_packing(*options, &block) if options.empty? || (Integer === options.first) || (String === options.first) || !seekable?
57
76
  return Enumerator.new(self, :each_with_packing, *options) unless block_given?
58
77
  yield read(*options) until eof?
59
78
  end
60
79
 
61
80
  def write_with_packing(*arg)
62
- (arg.length <= 1 || tty?) ? write_without_packing(*arg) : pack_and_write(*arg)
81
+ (arg.length <= 1 || !seekable?) ? write_without_packing(*arg) : pack_and_write(*arg)
63
82
  end
64
83
 
65
84
  def read_with_packing(*arg)
66
- return read_without_packing(*arg) if arg.empty? || arg.first.nil? || arg.first.is_a?(Numeric) || tty?
85
+ return read_without_packing(*arg) if arg.empty? || arg.first.nil? || arg.first.is_a?(Numeric) || !seekable?
67
86
  values = Packable::Packers.to_class_option_list(*arg).map do |klass, options, original|
68
87
  if options[:read_packed]
69
88
  options[:read_packed].call(self)
@@ -1,3 +1,3 @@
1
1
  module Packable
2
- VERSION = "1.3.13"
2
+ VERSION = "1.3.14"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.13
4
+ version: 1.3.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc-André Lafortune
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-07 00:00:00.000000000 Z
11
+ date: 2020-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backports