storable 0.8.9 → 0.9.pre.RC1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f22223588dad9fc35c869793a01e3bf186afd4a5ebdb0d4016a25ae75a317f18
4
+ data.tar.gz: 001b177ce5a50d59afe1123bb866591147bbddfe197a969c9cb01d80268cda31
5
+ SHA512:
6
+ metadata.gz: a103e403fc9017f6dfeab08c0b5ce0f886bfacff25294f24d8c0cd292069a7f69e23c91c1aef550f73fdab40d852295158b1f673ef87dd099c48fb03c42ebd19
7
+ data.tar.gz: 308682df363bcdb31822e10ee8b023bb329eadf30cf8a70664c8819e514f0d3f123b51cf57c8059bf6bc8c5445df1bd68225e82541e86fe31fb14cce3d17a969
@@ -1,76 +1,76 @@
1
- = Storable - v0.8
1
+ # Storable - v0.9-RC1
2
2
 
3
- Marshal Ruby classes into and out of multiple formats (yaml, json, csv, tsv)
3
+ Marshal Ruby classes in to and out of multiple formats (yaml, json, csv, tsv).
4
+
5
+ ## Example
4
6
 
5
- == Example
6
-
7
7
  require 'storable'
8
-
8
+
9
9
  class Machine < Storable
10
10
  field :environment # Define field names for Machine. The
11
11
  field :role # default type is String, but you can
12
12
  field :position => Integer # specify a type using a hash syntax.
13
13
  end
14
-
14
+
15
15
  mac1 = Machine.new # Instances of Machine have accessors
16
- mac1.environment = "stage" # just like regular attributes.
16
+ mac1.environment = "stage" # just like regular attributes.
17
17
  mac1.role = "app"
18
18
  mac1.position = 1
19
-
20
- puts "# YAML", mac1.to_yaml # Note: the field order is maintained
19
+
20
+ puts "# YAML", mac1.to_yaml # Note: the field order is maintained
21
21
  puts "# CSV", mac1.to_csv # => stage,app,1
22
22
  puts "# JSON", mac1.to_json # Note: field order not maintained.
23
-
23
+
24
24
  mac2 = Machine.from_yaml(mac1.to_yaml)
25
25
  puts mac2.environment # => "stage"
26
26
  puts mac2.position.class # => Fixnum
27
27
 
28
28
 
29
- == Sensitive Fields
29
+ ## Sensitive Fields
30
30
 
31
31
  require 'storable'
32
-
32
+
33
33
  class Calc < Storable
34
34
  field :three
35
35
  field :two
36
36
  field :one
37
37
  sensitive_fields :three
38
38
  end
39
-
39
+
40
40
  calc = Calc.new 3, 2, 1
41
41
  calc.to_a # => [3, 2, 1]
42
42
  calc.sensitive!
43
43
  calc.to_a # => [2, 1]
44
-
45
-
46
- == Storing Procs
47
44
 
48
- Storable can also marshal Proc objects to and from their actual source code.
49
-
45
+
46
+ ## Storing Procs
47
+
48
+ Storable can also marshal Proc objects to and from their actual source code.
49
+
50
50
  require 'storable'
51
-
51
+
52
52
  class Maths < Storable
53
53
  field :x => Float
54
54
  field :y => Float
55
55
  field :calculate => Proc
56
56
  end
57
-
57
+
58
58
  m1 = Maths.new 2.0, 3.0
59
59
  m1.calculate = Proc.new { @x * @y }
60
-
60
+
61
61
  m1.calculate.source # => "{ @x * @y }"
62
62
  m1.call :calculate # => 6.0
63
-
63
+
64
64
  dump = m1.to_json
65
-
65
+
66
66
  m2 = Maths.from_json dump
67
67
  m2.call :calculate # => 6.0
68
-
69
-
70
- Anything is possible when you keep your mind open and you use Ruby.
71
68
 
72
69
 
73
- == Installation
70
+ Anything is possible when you keep your mind open and you use Ruby.
71
+
72
+
73
+ ## Installation
74
74
 
75
75
  Via Rubygems, one of:
76
76
 
@@ -80,30 +80,30 @@ Via Rubygems, one of:
80
80
  or via download:
81
81
  * storable-latest.tar.gz[http://github.com/delano/storable/tarball/latest]
82
82
  * storable-latest.zip[http://github.com/delano/storable/zipball/latest]
83
-
84
83
 
85
- == Prerequisites
86
84
 
87
- * Ruby 1.8, Ruby 1.9, or JRuby 1.2+
85
+ ## Prerequisites
86
+
87
+ * Ruby <=2.7, >=1.9, possibly JRuby
88
88
 
89
89
 
90
- == Credits
90
+ ## Credits
91
91
 
92
92
  * Delano Mandelbaum (delano@solutious.com)
93
93
  * lib/proc_source.rb is based on http://github.com/imedo/background
94
94
  * OrderedHash implementation by Jan Molic
95
95
 
96
96
 
97
- == Thanks
97
+ ## Thanks
98
98
 
99
- * Pierre Riteau (priteau[https://github.com/priteau]) for bug fixes.
99
+ * Pierre Riteau (priteau[https://github.com/priteau]) for bug fixes.
100
100
  * notro[https://github.com/priteau] for proc_source improvements.
101
101
 
102
102
 
103
- == More Info
103
+ ## More Info
104
104
 
105
- * Codes[http://github.com/delano/storable]
105
+ * GitHub[http://github.com/delano/storable]
106
106
 
107
- == License
107
+ ## License
108
108
 
109
- See: LICENSE.txt
109
+ See: LICENSE.txt
data/Rakefile CHANGED
@@ -1,22 +1,17 @@
1
1
  require 'rubygems'
2
2
  require 'rake/clean'
3
- require 'rake/gempackagetask'
3
+ require 'rubygems/package_task'
4
4
  require 'fileutils'
5
+ require 'rdoc/task'
5
6
  include FileUtils
6
7
 
7
- begin
8
- require 'hanna/rdoctask'
9
- rescue LoadError
10
- require 'rake/rdoctask'
11
- end
12
-
13
8
  task :default => :package
14
-
9
+
10
+
15
11
  # CONFIG =============================================================
16
12
 
17
13
  # Change the following according to your needs
18
- README = "README.rdoc"
19
- CHANGES = "CHANGES.txt"
14
+ README = "README.md"
20
15
  LICENSE = "LICENSE.txt"
21
16
 
22
17
  # Files and directories to be deleted when you run "rake clean"
@@ -28,7 +23,7 @@ load "#{name}.gemspec"
28
23
  version = @spec.version
29
24
 
30
25
  # That's it! The following defaults should allow you to get started
31
- # on other things.
26
+ # on other things.
32
27
 
33
28
 
34
29
  # TESTS/SPECS =========================================================
@@ -39,7 +34,7 @@ end
39
34
 
40
35
  # INSTALL =============================================================
41
36
 
42
- Rake::GemPackageTask.new(@spec) do |p|
37
+ Gem::PackageTask.new(@spec) do |p|
43
38
  p.need_tar = true if RUBY_PLATFORM !~ /mswin/
44
39
  end
45
40
 
@@ -53,65 +48,15 @@ task :uninstall => [ :clean ] do
53
48
  end
54
49
 
55
50
 
56
- # RUBYFORGE RELEASE / PUBLISH TASKS ==================================
57
-
58
- if @spec.rubyforge_project
59
- desc 'Publish website to rubyforge'
60
- task 'publish:rdoc' => 'doc/index.html' do
61
- sh "scp -rp doc/* rubyforge.org:/var/www/gforge-projects/#{name}/"
62
- end
63
-
64
- desc 'Public release to rubyforge'
65
- task 'publish:gem' => [:package] do |t|
66
- sh <<-end
67
- rubyforge add_release -o Any -a #{CHANGES} -f -n #{README} #{name} #{name} #{@spec.version} pkg/#{name}-#{@spec.version}.gem &&
68
- rubyforge add_file -o Any -a #{CHANGES} -f -n #{README} #{name} #{name} #{@spec.version} pkg/#{name}-#{@spec.version}.tgz
69
- end
70
- end
71
- end
72
-
73
-
74
-
75
51
  # RUBY DOCS TASK ==================================
76
- begin
77
- require 'hanna/rdoctask'
78
- rescue LoadError
79
- require 'rake/rdoctask'
80
- end
81
52
 
82
- Rake::RDocTask.new do |t|
53
+ RDoc::Task.new do |t|
83
54
  t.rdoc_dir = 'doc'
84
55
  t.title = @spec.summary
85
56
  t.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
86
57
  t.options << '--charset' << 'utf-8'
87
58
  t.rdoc_files.include(LICENSE)
88
59
  t.rdoc_files.include(README)
89
- t.rdoc_files.include(CHANGES)
90
60
  #t.rdoc_files.include('bin/*')
91
61
  t.rdoc_files.include('lib/**/*.rb')
92
62
  end
93
-
94
-
95
-
96
-
97
- #Hoe.new('rspec', Spec::VERSION::STRING) do |p|
98
- # p.summary = Spec::VERSION::SUMMARY
99
- # p.description = "Behaviour Driven Development for Ruby."
100
- # p.rubyforge_name = 'rspec'
101
- # p.developer('RSpec Development Team', 'rspec-devel@rubyforge.org')
102
- # p.extra_dev_deps = [["cucumber",">= 0.1.13"]]
103
- # p.remote_rdoc_dir = "rspec/#{Spec::VERSION::STRING}"
104
- # p.rspec_options = ['--options', 'spec/spec.opts']
105
- # p.history_file = 'History.rdoc'
106
- # p.readme_file = 'README.rdoc'
107
- # p.post_install_message = <<-POST_INSTALL_MESSAGE
108
- ##{'*'*50}
109
- #
110
- # Thank you for installing rspec-#{Spec::VERSION::STRING}
111
- #
112
- # Please be sure to read History.rdoc and Upgrade.rdoc
113
- # for useful information about this release.
114
- #
115
- #{'*'*50}
116
- #POST_INSTALL_MESSAGE
117
- #end
data/lib/core_ext.rb ADDED
@@ -0,0 +1,273 @@
1
+
2
+ #
3
+ # RubyToken was removed in >= 2.7
4
+ # Direct copy from Ruby 2.6.6 source
5
+ #
6
+
7
+ # frozen_string_literal: false
8
+ #
9
+ # irb/ruby-token.rb - ruby tokens
10
+ # $Release Version: 0.9.6$
11
+ # $Revision$
12
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
13
+ #
14
+ # --
15
+ #
16
+ #
17
+ #
18
+ # :stopdoc:
19
+ module RubyToken
20
+ EXPR_BEG = :EXPR_BEG
21
+ EXPR_MID = :EXPR_MID
22
+ EXPR_END = :EXPR_END
23
+ EXPR_ARG = :EXPR_ARG
24
+ EXPR_FNAME = :EXPR_FNAME
25
+ EXPR_DOT = :EXPR_DOT
26
+ EXPR_CLASS = :EXPR_CLASS
27
+
28
+ class Token
29
+ def initialize(seek, line_no, char_no)
30
+ @seek = seek
31
+ @line_no = line_no
32
+ @char_no = char_no
33
+ end
34
+ attr_reader :seek, :line_no, :char_no
35
+ end
36
+
37
+ class TkNode < Token
38
+ def initialize(seek, line_no, char_no)
39
+ super
40
+ end
41
+ attr_reader :node
42
+ end
43
+
44
+ class TkId < Token
45
+ def initialize(seek, line_no, char_no, name)
46
+ super(seek, line_no, char_no)
47
+ @name = name
48
+ end
49
+ attr_reader :name
50
+ end
51
+
52
+ class TkVal < Token
53
+ def initialize(seek, line_no, char_no, value = nil)
54
+ super(seek, line_no, char_no)
55
+ @value = value
56
+ end
57
+ attr_reader :value
58
+ end
59
+
60
+ class TkOp < Token
61
+ attr_accessor :name
62
+ end
63
+
64
+ class TkOPASGN < TkOp
65
+ def initialize(seek, line_no, char_no, op)
66
+ super(seek, line_no, char_no)
67
+ op = TkReading2Token[op][0] unless op.kind_of?(Symbol)
68
+ @op = op
69
+ end
70
+ attr_reader :op
71
+ end
72
+
73
+ class TkUnknownChar < Token
74
+ def initialize(seek, line_no, char_no, id)
75
+ super(seek, line_no, char_no)
76
+ @name = name
77
+ end
78
+ attr_reader :name
79
+ end
80
+
81
+ class TkError < Token
82
+ end
83
+
84
+ def Token(token, value = nil)
85
+ case token
86
+ when String
87
+ if (tk = TkReading2Token[token]).nil?
88
+ IRB.fail TkReading2TokenNoKey, token
89
+ end
90
+ tk = Token(tk[0], value)
91
+ if tk.kind_of?(TkOp)
92
+ tk.name = token
93
+ end
94
+ return tk
95
+ when Symbol
96
+ if (tk = TkSymbol2Token[token]).nil?
97
+ IRB.fail TkSymbol2TokenNoKey, token
98
+ end
99
+ return Token(tk[0], value)
100
+ else
101
+ if (token.ancestors & [TkId, TkVal, TkOPASGN, TkUnknownChar]).empty?
102
+ token.new(@prev_seek, @prev_line_no, @prev_char_no)
103
+ else
104
+ token.new(@prev_seek, @prev_line_no, @prev_char_no, value)
105
+ end
106
+ end
107
+ end
108
+
109
+ TokenDefinitions = [
110
+ [:TkCLASS, TkId, "class", EXPR_CLASS],
111
+ [:TkMODULE, TkId, "module", EXPR_BEG],
112
+ [:TkDEF, TkId, "def", EXPR_FNAME],
113
+ [:TkUNDEF, TkId, "undef", EXPR_FNAME],
114
+ [:TkBEGIN, TkId, "begin", EXPR_BEG],
115
+ [:TkRESCUE, TkId, "rescue", EXPR_MID],
116
+ [:TkENSURE, TkId, "ensure", EXPR_BEG],
117
+ [:TkEND, TkId, "end", EXPR_END],
118
+ [:TkIF, TkId, "if", EXPR_BEG, :TkIF_MOD],
119
+ [:TkUNLESS, TkId, "unless", EXPR_BEG, :TkUNLESS_MOD],
120
+ [:TkTHEN, TkId, "then", EXPR_BEG],
121
+ [:TkELSIF, TkId, "elsif", EXPR_BEG],
122
+ [:TkELSE, TkId, "else", EXPR_BEG],
123
+ [:TkCASE, TkId, "case", EXPR_BEG],
124
+ [:TkWHEN, TkId, "when", EXPR_BEG],
125
+ [:TkWHILE, TkId, "while", EXPR_BEG, :TkWHILE_MOD],
126
+ [:TkUNTIL, TkId, "until", EXPR_BEG, :TkUNTIL_MOD],
127
+ [:TkFOR, TkId, "for", EXPR_BEG],
128
+ [:TkBREAK, TkId, "break", EXPR_END],
129
+ [:TkNEXT, TkId, "next", EXPR_END],
130
+ [:TkREDO, TkId, "redo", EXPR_END],
131
+ [:TkRETRY, TkId, "retry", EXPR_END],
132
+ [:TkIN, TkId, "in", EXPR_BEG],
133
+ [:TkDO, TkId, "do", EXPR_BEG],
134
+ [:TkRETURN, TkId, "return", EXPR_MID],
135
+ [:TkYIELD, TkId, "yield", EXPR_END],
136
+ [:TkSUPER, TkId, "super", EXPR_END],
137
+ [:TkSELF, TkId, "self", EXPR_END],
138
+ [:TkNIL, TkId, "nil", EXPR_END],
139
+ [:TkTRUE, TkId, "true", EXPR_END],
140
+ [:TkFALSE, TkId, "false", EXPR_END],
141
+ [:TkAND, TkId, "and", EXPR_BEG],
142
+ [:TkOR, TkId, "or", EXPR_BEG],
143
+ [:TkNOT, TkId, "not", EXPR_BEG],
144
+ [:TkIF_MOD, TkId],
145
+ [:TkUNLESS_MOD, TkId],
146
+ [:TkWHILE_MOD, TkId],
147
+ [:TkUNTIL_MOD, TkId],
148
+ [:TkALIAS, TkId, "alias", EXPR_FNAME],
149
+ [:TkDEFINED, TkId, "defined?", EXPR_END],
150
+ [:TklBEGIN, TkId, "BEGIN", EXPR_END],
151
+ [:TklEND, TkId, "END", EXPR_END],
152
+ [:Tk__LINE__, TkId, "__LINE__", EXPR_END],
153
+ [:Tk__FILE__, TkId, "__FILE__", EXPR_END],
154
+
155
+ [:TkIDENTIFIER, TkId],
156
+ [:TkFID, TkId],
157
+ [:TkGVAR, TkId],
158
+ [:TkCVAR, TkId],
159
+ [:TkIVAR, TkId],
160
+ [:TkCONSTANT, TkId],
161
+
162
+ [:TkINTEGER, TkVal],
163
+ [:TkFLOAT, TkVal],
164
+ [:TkSTRING, TkVal],
165
+ [:TkXSTRING, TkVal],
166
+ [:TkREGEXP, TkVal],
167
+ [:TkSYMBOL, TkVal],
168
+
169
+ [:TkDSTRING, TkNode],
170
+ [:TkDXSTRING, TkNode],
171
+ [:TkDREGEXP, TkNode],
172
+ [:TkNTH_REF, TkNode],
173
+ [:TkBACK_REF, TkNode],
174
+
175
+ [:TkUPLUS, TkOp, "+@"],
176
+ [:TkUMINUS, TkOp, "-@"],
177
+ [:TkPOW, TkOp, "**"],
178
+ [:TkCMP, TkOp, "<=>"],
179
+ [:TkEQ, TkOp, "=="],
180
+ [:TkEQQ, TkOp, "==="],
181
+ [:TkNEQ, TkOp, "!="],
182
+ [:TkGEQ, TkOp, ">="],
183
+ [:TkLEQ, TkOp, "<="],
184
+ [:TkANDOP, TkOp, "&&"],
185
+ [:TkOROP, TkOp, "||"],
186
+ [:TkMATCH, TkOp, "=~"],
187
+ [:TkNMATCH, TkOp, "!~"],
188
+ [:TkDOT2, TkOp, ".."],
189
+ [:TkDOT3, TkOp, "..."],
190
+ [:TkAREF, TkOp, "[]"],
191
+ [:TkASET, TkOp, "[]="],
192
+ [:TkLSHFT, TkOp, "<<"],
193
+ [:TkRSHFT, TkOp, ">>"],
194
+ [:TkCOLON2, TkOp],
195
+ [:TkCOLON3, TkOp],
196
+ [:TkASSOC, TkOp, "=>"],
197
+ [:TkQUESTION, TkOp, "?"], #?
198
+ [:TkCOLON, TkOp, ":"], #:
199
+
200
+ [:TkfLPAREN], # func( #
201
+ [:TkfLBRACK], # func[ #
202
+ [:TkfLBRACE], # func{ #
203
+ [:TkSTAR], # *arg
204
+ [:TkAMPER], # &arg #
205
+ [:TkSYMBEG], # :SYMBOL
206
+
207
+ [:TkGT, TkOp, ">"],
208
+ [:TkLT, TkOp, "<"],
209
+ [:TkPLUS, TkOp, "+"],
210
+ [:TkMINUS, TkOp, "-"],
211
+ [:TkMULT, TkOp, "*"],
212
+ [:TkDIV, TkOp, "/"],
213
+ [:TkMOD, TkOp, "%"],
214
+ [:TkBITOR, TkOp, "|"],
215
+ [:TkBITXOR, TkOp, "^"],
216
+ [:TkBITAND, TkOp, "&"],
217
+ [:TkBITNOT, TkOp, "~"],
218
+ [:TkNOTOP, TkOp, "!"],
219
+
220
+ [:TkBACKQUOTE, TkOp, "`"],
221
+
222
+ [:TkASSIGN, Token, "="],
223
+ [:TkDOT, Token, "."],
224
+ [:TkLPAREN, Token, "("], #(exp)
225
+ [:TkLBRACK, Token, "["], #[arry]
226
+ [:TkLBRACE, Token, "{"], #{hash}
227
+ [:TkRPAREN, Token, ")"],
228
+ [:TkRBRACK, Token, "]"],
229
+ [:TkRBRACE, Token, "}"],
230
+ [:TkCOMMA, Token, ","],
231
+ [:TkSEMICOLON, Token, ";"],
232
+
233
+ [:TkCOMMENT],
234
+ [:TkRD_COMMENT],
235
+ [:TkSPACE],
236
+ [:TkNL],
237
+ [:TkEND_OF_SCRIPT],
238
+
239
+ [:TkBACKSLASH, TkUnknownChar, "\\"],
240
+ [:TkAT, TkUnknownChar, "@"],
241
+ [:TkDOLLAR, TkUnknownChar, "$"],
242
+ ]
243
+
244
+ # {reading => token_class}
245
+ # {reading => [token_class, *opt]}
246
+ TkReading2Token = {}
247
+ TkSymbol2Token = {}
248
+
249
+ def RubyToken.def_token(token_n, super_token = Token, reading = nil, *opts)
250
+ token_n = token_n.id2name if token_n.kind_of?(Symbol)
251
+ if RubyToken.const_defined?(token_n)
252
+ IRB.fail AlreadyDefinedToken, token_n
253
+ end
254
+ token_c = eval("class #{token_n} < #{super_token}; end; #{token_n}")
255
+
256
+ if reading
257
+ if TkReading2Token[reading]
258
+ IRB.fail TkReading2TokenDuplicateError, token_n, reading
259
+ end
260
+ if opts.empty?
261
+ TkReading2Token[reading] = [token_c]
262
+ else
263
+ TkReading2Token[reading] = [token_c].concat(opts)
264
+ end
265
+ end
266
+ TkSymbol2Token[token_n.intern] = token_c
267
+ end
268
+
269
+ for defs in TokenDefinitions
270
+ def_token(*defs)
271
+ end
272
+ end
273
+ # :startdoc:
data/lib/proc_source.rb CHANGED
@@ -1,24 +1,34 @@
1
- #--
1
+
2
+ #
2
3
  # Based on:
3
- # http://github.com/imedo/background
4
+ # https://github.com/imedo/background
5
+ # https://github.com/imedo/background_lite
4
6
  # With improvements by:
5
7
  # https://github.com/notro/storable
6
- #++
8
+ #
9
+
10
+ begin
11
+ require 'irb/ruby-token' # ruby <2.7
12
+ rescue
13
+ require 'lib/core_ext' # ruby >=2.7
14
+ end
7
15
 
8
- require 'stringio'
9
16
  require 'irb/ruby-lex'
10
- #SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
17
+ require 'stringio'
18
+
19
+ SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
20
+
11
21
 
12
22
  class ProcString < String
13
23
  # Filename where the proc is defined
14
24
  attr_accessor :file
15
-
25
+
16
26
  # Range of lines where the proc is defined
17
27
  # ex. (12..16)
18
28
  attr_accessor :lines
19
-
29
+
20
30
  attr_accessor :arity, :kind # :nodoc: FIXME: Should be removed?
21
-
31
+
22
32
  # Return a Proc object
23
33
  # If #lines and #file is specified, these are tied to the proc.
24
34
  def to_proc(kind="proc")
@@ -31,7 +41,7 @@ class ProcString < String
31
41
  result.source = self
32
42
  result
33
43
  end
34
-
44
+
35
45
  # Return a lambda
36
46
  def to_lambda
37
47
  to_proc "lambda"
@@ -39,100 +49,108 @@ class ProcString < String
39
49
  end
40
50
 
41
51
  class RubyToken::Token
42
-
43
- # These EXPR_BEG tokens don't have associated end tags
44
- FAKIES = [RubyToken::TkWHEN, RubyToken::TkELSIF, RubyToken::TkELSE, RubyToken::TkTHEN]
45
-
52
+
53
+ # These EXPR_BEG tokens don't have associated end tags
54
+ FAKIES = [
55
+ RubyToken::TkWHEN,
56
+ RubyToken::TkELSIF,
57
+ RubyToken::TkELSE,
58
+ RubyToken::TkTHEN,
59
+ ]
60
+
46
61
  def name
47
62
  @name ||= nil
48
63
  end
49
-
64
+
50
65
  def open_tag?
51
66
  return false if name.nil? || get_props.nil?
52
- a = (get_props[1] == RubyToken::EXPR_BEG) &&
53
- self.class.to_s !~ /_MOD/ && # ignore onliner if, unless, etc...
54
- !FAKIES.member?(self.class)
55
- a
67
+ is_open = (
68
+ (get_props[1] == RubyToken::EXPR_BEG) &&
69
+ (self.class.to_s !~ /_MOD/) && # ignore onliner if, unless, etc...
70
+ (!FAKIES.member?(self.class))
71
+ )
72
+ is_open
56
73
  end
57
-
74
+
58
75
  def get_props
59
76
  RubyToken::TkReading2Token[name]
60
77
  end
61
-
78
+
62
79
  end
63
80
 
64
81
  # Based heavily on code from http://github.com/imedo/background
65
82
  # Big thanks to the imedo dev team!
66
83
  #
67
84
  module ProcSource
68
-
85
+
69
86
  def self.find(filename, start_line=1, block_only=true)
70
87
  lines, lexer = nil, nil
71
88
  retried = 0
72
89
  loop do
73
90
  lines = get_lines(filename, start_line)
91
+ # binding.pry
74
92
  return nil if lines.nil?
75
- #p [start_line, lines[0]]
76
93
  if !line_has_open?(lines.join) && start_line >= 0
77
- start_line -= 1 and retried +=1 and redo
94
+ start_line -= 1 and retried +=1 and redo
78
95
  end
79
96
  lexer = RubyLex.new
80
97
  lexer.set_input(StringIO.new(lines.join))
81
98
  break
82
99
  end
100
+
83
101
  stoken, etoken, nesting = nil, nil, 0
84
102
  while token = lexer.token
85
- n = token.name
86
-
87
103
  if RubyToken::TkIDENTIFIER === token
88
- #nothing
104
+ # nothing
89
105
  elsif token.open_tag? || RubyToken::TkfLBRACE === token
90
106
  nesting += 1
91
107
  stoken = token if nesting == 1
92
108
  elsif RubyToken::TkEND === token || RubyToken::TkRBRACE === token
93
109
  if nesting == 1
94
- etoken = token
110
+ etoken = token
95
111
  break
96
112
  end
97
113
  nesting -= 1
98
114
  elsif RubyToken::TkLBRACE === token
99
115
  nesting += 1
100
116
  elsif RubyToken::TkBITOR === token && stoken
101
- #nothing
117
+ # nothing
102
118
  elsif RubyToken::TkNL === token && stoken && etoken
103
119
  break if nesting <= 0
104
120
  else
105
- #p token
121
+ # nothing
106
122
  end
107
123
  end
108
- # puts lines if etoken.nil?
124
+
125
+ # binding.pry
126
+
109
127
  lines = lines[stoken.line_no-1 .. etoken.line_no-1]
110
-
111
- # Remove the crud before the block definition.
128
+
129
+ # Remove the crud before the block definition.
112
130
  if block_only
113
131
  spaces = lines.last.match(/^\s+/)[0] rescue ''
114
132
  lines[0] = spaces << lines[0][stoken.char_no .. -1]
115
133
  end
116
134
  ps = ProcString.new lines.join
117
- ps.file, ps.lines = filename, start_line .. start_line+etoken.line_no-1
118
-
135
+ ps.file = filename
136
+ ps.lines = start_line .. start_line+etoken.line_no-1
119
137
  ps
120
138
  end
121
-
139
+
122
140
  # A hack for Ruby 1.9, otherwise returns true.
123
141
  #
124
142
  # Ruby 1.9 returns an incorrect line number
125
143
  # when a block is specified with do/end. It
126
- # happens b/c the line number returned by
144
+ # happens b/c the line number returned by
127
145
  # Ruby 1.9 is based on the first line in the
128
146
  # block which contains a token (i.e. not a
129
- # new line or comment etc...).
147
+ # new line or comment etc...).
130
148
  #
131
- # NOTE: This won't work in cases where the
132
- # incorrect line also contains a "do".
149
+ # NOTE: This won't work in cases where the
150
+ # incorrect line also contains a "do".
133
151
  #
134
152
  def self.line_has_open?(str)
135
- return true unless RUBY_VERSION >= '1.9'
153
+ return true unless RUBY_VERSION >= '1.9' && RUBY_VERSION < '2.0'
136
154
  lexer = RubyLex.new
137
155
  lexer.set_input(StringIO.new(str))
138
156
  success = false
@@ -157,20 +175,26 @@ module ProcSource
157
175
  end
158
176
  success
159
177
  end
160
-
161
-
178
+
162
179
  def self.get_lines(filename, start_line = 1)
163
180
  case filename
164
181
  when nil
165
182
  nil
166
- when "(irb)" # special "(irb)" descriptor?
183
+
184
+ # We're in irb
185
+ when "(irb)"
167
186
  IRB.conf[:MAIN_CONTEXT].io.line(start_line .. -2)
168
- when /^\(eval.+\)$/ # special "(eval...)" descriptor?
187
+
188
+ # Or an eval
189
+ when /^\(eval.+\)$/
169
190
  EVAL_LINES__[filename][start_line .. -2]
170
- else # regular file
191
+
192
+ # Or most likely a .rb file
193
+ else
171
194
  # Ruby already parsed this file? (see disclaimer above)
172
195
  if defined?(SCRIPT_LINES__) && SCRIPT_LINES__[filename]
173
196
  SCRIPT_LINES__[filename][(start_line - 1) .. -1]
197
+
174
198
  # If the file exists we're going to try reading it in
175
199
  elsif File.exist?(filename)
176
200
  begin
@@ -183,35 +207,42 @@ module ProcSource
183
207
  end
184
208
  end
185
209
 
186
- class Proc #:nodoc:
210
+ class Proc # :nodoc:
187
211
  attr_writer :source
188
-
212
+ @@regexp = Regexp.new('^#<Proc:0x[0-9A-Fa-f]+@?\s*(.+):(\d+)(.+?)?>$')
213
+
189
214
  def source_descriptor
190
- @file ||= nil
191
- @line ||= nil
192
- unless @file && @line
193
- if md = /^#<Proc:0x[0-9A-Fa-f]+@(.+):(\d+)(.+?)?>$/.match(inspect)
194
- @file, @line = md.captures
195
- end
215
+ return [@file, @line] if @file && @line
216
+
217
+ source_location = nil
218
+ if RUBY_VERSION >= '2.7'
219
+ source_location = *self.source_location
220
+ else
221
+ inspection = inspect
222
+ md = @@regexp.match(inspection)
223
+ exmsg = 'Unable to parse proc inspect (%s)' % inspection
224
+ raise Exception, exmsg if md.nil?
225
+ source_location = md.captures
196
226
  end
197
- @line = @line.to_i
198
- [@file, @line]
227
+
228
+ file, line = *source_location
229
+ @file, @line = [file, line.to_i]
199
230
  end
200
-
231
+
201
232
  def source
202
233
  @source ||= ProcSource.find(*self.source_descriptor)
203
234
  end
204
-
235
+
205
236
  def line
206
237
  source_descriptor
207
238
  @line
208
239
  end
209
-
240
+
210
241
  def file
211
242
  source_descriptor
212
243
  @file
213
244
  end
214
-
245
+
215
246
  # Dump to Marshal format.
216
247
  # p = Proc.new { false }
217
248
  # Marshal.dump p
@@ -220,7 +251,7 @@ class Proc #:nodoc:
220
251
  str = Marshal.dump(source)
221
252
  str
222
253
  end
223
-
254
+
224
255
  # Load from Marshal format.
225
256
  # p = Proc.new { false }
226
257
  # Marshal.load Marshal.dump p
@@ -228,7 +259,7 @@ class Proc #:nodoc:
228
259
  @source = Marshal.load(str)
229
260
  @source.to_proc
230
261
  end
231
-
262
+
232
263
  # Dump to JSON string
233
264
  def to_json(*args)
234
265
  raise "can't serialize proc, #source is nil" if source.nil?
@@ -237,7 +268,7 @@ class Proc #:nodoc:
237
268
  'data' => [source.to_s, source.file, source.lines.min, source.lines.max]
238
269
  }.to_json#(*args)
239
270
  end
240
-
271
+
241
272
  def self.json_create(o)
242
273
  s, file, min, max = o['data']
243
274
  ps = ProcString.new s
@@ -245,8 +276,8 @@ class Proc #:nodoc:
245
276
  ps.lines = (min..max)
246
277
  ps.to_proc
247
278
  end
248
-
249
- # Create a Proc object from a string of Ruby code.
279
+
280
+ # Create a Proc object from a string of Ruby code.
250
281
  # It's assumed the string contains do; end or { }.
251
282
  #
252
283
  # Proc.from_string("do; 2+2; end")
@@ -254,7 +285,7 @@ class Proc #:nodoc:
254
285
  def self.from_string(str)
255
286
  eval "Proc.new #{str}"
256
287
  end
257
-
288
+
258
289
  end
259
290
 
260
291
  if $0 == __FILE__
@@ -267,17 +298,17 @@ if $0 == __FILE__
267
298
  end
268
299
 
269
300
  a = Proc.new() { |a|
270
- puts "Hello Rudy2"
301
+ puts "Hello Rudy2"
271
302
  }
272
-
303
+
273
304
  b = Proc.new() do |b|
274
305
  puts { "Hello Rudy3" } if true
275
306
  end
276
-
307
+
277
308
  puts @blk.inspect, @blk.source
278
309
  puts [a.inspect, a.source]
279
310
  puts b.inspect, b.source
280
-
311
+
281
312
  proc = @blk.source.to_proc
282
313
  proc.call(1)
283
314
  end
data/storable.gemspec CHANGED
@@ -1,43 +1,23 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = "storable"
3
- s.rubyforge_project = "storable"
4
- s.version = "0.8.9"
5
- s.summary = "Storable: Marshal Ruby classes into and out of multiple formats (yaml, json, csv, tsv)"
6
- s.description = s.summary
7
- s.author = "Delano Mandelbaum"
8
- s.email = "delano@solutious.com"
9
- s.homepage = "http://github.com/delano/storable/"
10
-
11
-
12
- # = EXECUTABLES =
13
- # The list of executables in your project (if any). Don't include the path,
14
- # just the base filename.
15
- s.executables = %w[]
16
-
17
- # = DEPENDENCIES =
18
- # Add all gem dependencies
19
-
20
- # = MANIFEST =
21
- # The complete list of files to be included in the release. When GitHub packages your gem,
22
- # it doesn't allow you to run any command that accesses the filesystem. You will get an
23
- # error. You can ask your VCS for the list of versioned files:
24
- # git ls-files
25
- # svn list -R
3
+ s.version = "0.9-RC1"
4
+ s.summary = "Ruby classes as strings"
5
+ s.description = "Storable: Marshal Ruby classes into and out of multiple formats (yaml, json, csv, tsv)"
6
+ s.authors = ["Delano Mandelbaum"]
7
+ s.email = "gems@solutious.com"
8
+ s.homepage = "https://github.com/delano/storable/"
9
+ s.licenses = ["MIT"] # https://spdx.org/licenses/MIT-Modern-Variant.html
26
10
  s.files = %w(
27
- CHANGES.txt
28
- LICENSE.txt
29
- README.rdoc
30
- Rakefile
31
- lib/proc_source.rb
32
- lib/storable.rb
33
- lib/storable/orderedhash.rb
34
- storable.gemspec
11
+ README.md
12
+ Rakefile
13
+ lib/core_ext.rb
14
+ lib/proc_source.rb
15
+ lib/storable.rb
16
+ lib/storable/orderedhash.rb
17
+ storable.gemspec
35
18
  )
36
-
37
- s.extra_rdoc_files = %w[README.rdoc LICENSE.txt]
38
- s.has_rdoc = true
39
- s.rdoc_options = ["--line-numbers", "--title", s.summary, "--main", "README.rdoc"]
19
+ s.extra_rdoc_files = %w[README.md]
20
+ s.rdoc_options = ["--line-numbers", "--title", s.summary, "--main", "README.md"]
40
21
  s.require_paths = %w[lib]
41
- s.rubygems_version = '1.3.0'
42
-
43
- end
22
+ s.rubygems_version = '3.2.21'
23
+ end
metadata CHANGED
@@ -1,68 +1,56 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: storable
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.8.9
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.pre.RC1
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Delano Mandelbaum
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2011-05-21 00:00:00 -04:00
14
- default_executable:
11
+ date: 2021-07-02 00:00:00.000000000 Z
15
12
  dependencies: []
16
-
17
- description: "Storable: Marshal Ruby classes into and out of multiple formats (yaml, json, csv, tsv)"
18
- email: delano@solutious.com
13
+ description: 'Storable: Marshal Ruby classes into and out of multiple formats (yaml,
14
+ json, csv, tsv)'
15
+ email: gems@solutious.com
19
16
  executables: []
20
-
21
17
  extensions: []
22
-
23
- extra_rdoc_files:
24
- - README.rdoc
25
- - LICENSE.txt
26
- files:
27
- - CHANGES.txt
28
- - LICENSE.txt
29
- - README.rdoc
18
+ extra_rdoc_files:
19
+ - README.md
20
+ files:
21
+ - README.md
30
22
  - Rakefile
23
+ - lib/core_ext.rb
31
24
  - lib/proc_source.rb
32
25
  - lib/storable.rb
33
26
  - lib/storable/orderedhash.rb
34
27
  - storable.gemspec
35
- has_rdoc: true
36
- homepage: http://github.com/delano/storable/
37
- licenses: []
38
-
28
+ homepage: https://github.com/delano/storable/
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
39
32
  post_install_message:
40
- rdoc_options:
41
- - --line-numbers
42
- - --title
43
- - "Storable: Marshal Ruby classes into and out of multiple formats (yaml, json, csv, tsv)"
44
- - --main
45
- - README.rdoc
46
- require_paths:
33
+ rdoc_options:
34
+ - "--line-numbers"
35
+ - "--title"
36
+ - Ruby classes as strings
37
+ - "--main"
38
+ - README.md
39
+ require_paths:
47
40
  - lib
48
- required_ruby_version: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
51
43
  - - ">="
52
- - !ruby/object:Gem::Version
53
- version: "0"
54
- required_rubygems_version: !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- version: "0"
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">"
49
+ - !ruby/object:Gem::Version
50
+ version: 1.3.1
60
51
  requirements: []
61
-
62
- rubyforge_project: storable
63
- rubygems_version: 1.5.2
52
+ rubygems_version: 3.2.14
64
53
  signing_key:
65
- specification_version: 3
66
- summary: "Storable: Marshal Ruby classes into and out of multiple formats (yaml, json, csv, tsv)"
54
+ specification_version: 4
55
+ summary: Ruby classes as strings
67
56
  test_files: []
68
-
data/CHANGES.txt DELETED
@@ -1,168 +0,0 @@
1
- STORABLE, CHANGES
2
-
3
- * TODO: https://github.com/delano/storable/pull/2
4
- * TODO: Handle nested hashes and arrays.
5
-
6
- #### 0.8.9 (GREAT RAPTURE) ##########################
7
-
8
- * FIXED: Removed bad default value setting.
9
-
10
- #### 0.8.8 (2011-05-20) #############################
11
-
12
- * ADDED: Storable.field can now take and store Hash options (:default, :meth)
13
-
14
- #### 0.8.7 (2011-??-??) #############################
15
-
16
- * ?
17
-
18
- #### 0.8.6 (2010-12-31) #############################
19
-
20
- * ADDED: Re-added a default initialize that defers to the default init
21
-
22
- #### 0.8.5 (2010-12-29) #############################
23
-
24
- * FIXED: Added calls to preprocess in the to_FORMAT methods.
25
- * FIXED: Added calls to postprocess in from_delimited
26
- * CHANGE: Remove initialize completely
27
- * ADDED: Storable#from_array (instance method)
28
- * ADDED: Storable#init (a default for Familia objects)
29
-
30
-
31
- #### 0.8.4 (2010-12-23) #############################
32
-
33
- * CHANGE: Moved initialize logic to Storable.from_array.
34
-
35
- NOTE: Classes that rely on this logic when creating
36
- new instances will need to call from_array instead!
37
-
38
-
39
- #### 0.8.3 (2010-11-02) #############################
40
-
41
- * FIXED: Handling of Boolean fields when the value is null.
42
- * CHANGE: from_hash explicitly checks field names as Symbols and Strings
43
-
44
-
45
- #### 0.8.2 (2010-09-05) #############################
46
-
47
- * FIXED: undefined method `each_pair' for nil:NilClass for hash_proc_processor
48
-
49
- #### 0.8.1 (2010-07-31) #############################
50
-
51
- * CHANGE: to_delimited and from_delimited are sensitive. This means you need to keep
52
- track of data that is sensitive.
53
-
54
- #### 0.8.0 (2010-07-28) #############################
55
-
56
- * FIXED: from_delimited now gracefully handles String input by splitting it by $/
57
- * CHANGE: Removed field name magic from from_delimited
58
- * CHANGE: Converted to Tryouts 2
59
- * ADDED: Support for sensitive fields
60
- * ADDED: Supports inheritance
61
- * ADDED: Storable#to_array
62
-
63
-
64
- #### 0.7.4 (2010-05-01) #############################
65
-
66
- * FIXED: Check separately if getter and setter methods are already defined
67
- * ADDED: Call Storable#preprocessor after an object is initialized
68
-
69
-
70
- #### 0.7.3 (2010-04-10) #############################
71
-
72
- * ADDED: Allow anonymous objects via Storable.from_json etc.
73
- * ADDED: Enabled support for marshalling Proc objects in IRB sessions.
74
- * ADDED: Storable#call for calling Proc fields via instance_eval
75
- * ADDED: Support for Range field type (parse from a String when necessary)
76
-
77
-
78
- #### 0.7.2 (2010-04-06) #############################
79
-
80
- * FIXED: Handle empty symbols like in Storable 0.6.4. Fixes "interning empty string" error. [Diego Elio 'Flameeyes' Pettenò]
81
-
82
- #### 0.7.1 (2010-04-04) #############################
83
-
84
- * FIXED: Missing proc_source.rb in gemspec.
85
-
86
- #### 0.7.0 (2010-04-03) #############################
87
-
88
- * FIXED: Default initialize method missed the last argument
89
- * FIXED: Possible error in from_hash when a value is nil
90
- * CHANGE: Remove unused "require 'fileutils'"
91
- * CHANGE: field_types is now a Hash
92
- * CHANGE: Set the instance variable if a setter method doesn't exist.
93
- * CHANGE: Will grab the first element of an Array if there is only one
94
- and a field type is defined that is not an Array.
95
- * ADDED: Storable.debug
96
- * ADDED: Boolean class (candy for TrueClass fields)
97
- * ADDED: Automatically convert a Proc to a string of its source in to_hash
98
- * ADDED: Support for Symbol field type
99
-
100
-
101
- #### 0.6.5 (2010-03-23) #############################
102
-
103
- * ADDED: Use Yajl if it's available.
104
-
105
- #### 0.6.4 (2010-03-10) #############################
106
-
107
- * FIXED: Don't pull the first value out of an array if there is only one element.
108
- * FIXED: Stored Arrays were nested in another Array in some cases
109
-
110
- #### 0.6.2 (2010-02-12) #############################
111
-
112
- * CHANGE: Removed hanna dependency [Diego Elio 'Flameeyes' Pettenò]
113
-
114
- #### 0.6.1 (2010-01-15) #############################
115
-
116
- * ADDED: Default initialize for Storable objects which can set field values.
117
-
118
- #### 0.6.0 (2009-11-27) #############################
119
-
120
- * FIXED: Undefined @@field_names error when no fields specified
121
- * ADDED: Support for field output processors
122
- * ADDED: Storable::DefaultProcessors
123
-
124
-
125
- #### 0.5.8 (2009-10-06) #############################
126
-
127
- * FIXED: "wrong argument type false (expected Hash)". I think
128
- that's the last of it.
129
- * CHANGE: Removed with_titles argument for Storable#dump.
130
-
131
-
132
- #### 0.5.7 (2009-09-15) #############################
133
-
134
- * FIXED: "wrong argument type String (expected Data)" in to_yaml (finally!)
135
-
136
- #### 0.5.6 (2009-07-19) #############################
137
-
138
- * ADDED: has_field?
139
-
140
- #### 0.5.5 (2009-07-17) #############################
141
-
142
- * FIXED: require 'time' for Time.parse.
143
-
144
- #### 0.5.4 (2009-05-25) #############################
145
-
146
- * CHANGE: Removed RedCloth dependency from gemspec.
147
-
148
- #### 0.5.3 (2009-05-12) #############################
149
-
150
- * FIXED: Corrected error handling when json not available (ignore and continue)
151
-
152
- #### 0.5.2 (2009-05-12) #############################
153
-
154
- * CHANGE: Put OrderedHash into Storable namespace and imported merge fix from Caesars
155
- * FIXED: Circular dependency with Sysinfo
156
-
157
-
158
- #### 0.5.1 (2009-05-07) #############################
159
-
160
- * FIXED: Bug in from_hash which was incorrectly parsing some data types (incl. Integer)
161
- * ADDED: bin/example
162
- * ADDED: OrderedHash for Ruby 1.8.x (still unordered in JRuby. Need to investigate.)
163
-
164
- #### 0.5 (2009-05-07) ###############################
165
-
166
- * First public release. See commit history for solutious-stella, solutious-rudy,
167
- and delano-delanotes for complete history of SysInfo (was SystemInfo).
168
-
data/LICENSE.txt DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) 2009 Delano Mandelbaum, Solutious Inc
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.