flay-persistence 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ r���W�U�<�4����a��'6��%�c J/J=�/'u��ȡZI�V���yDQ_��L���ۇ�-L��:v��?�a�H�҄��
2
+ ��鷩�`�BOS���7Vxr�@5y�0������3��j'�`j�k�� i�d�1�`Y^lF^�� �v�����Y&Z$&���qz�ߟ�
3
+ O�m_���*V'�څ� ��
@@ -0,0 +1,26 @@
1
+ # -*- ruby -*-
2
+
3
+ require "autotest/restart"
4
+
5
+ Autotest.add_hook :initialize do |at|
6
+ at.testlib = "minitest/autorun"
7
+ at.add_exception "tmp"
8
+
9
+ # at.extra_files << "../some/external/dependency.rb"
10
+ #
11
+ # at.libs << ":../some/external"
12
+ #
13
+ # at.add_exception "vendor"
14
+ #
15
+ # at.add_mapping(/dependency.rb/) do |f, _|
16
+ # at.files_matching(/test_.*rb$/)
17
+ # end
18
+ #
19
+ # %w(TestA TestB).each do |klass|
20
+ # at.extra_class_map[klass] = "test/test_misc.rb"
21
+ # end
22
+ end
23
+
24
+ # Autotest.add_hook :run_command do |at|
25
+ # system "rake build"
26
+ # end
File without changes
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2013-02-13
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,8 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ lib/flay_persistence.rb
7
+ lib/stable_hash.rb
8
+ test/flay/test_persistence.rb
@@ -0,0 +1,56 @@
1
+ = flay-persistence
2
+
3
+ home :: https://github.com/seattlerb/flay-persistence
4
+ rdoc :: http://docs.seattlerb.org/flay-persistence
5
+
6
+ == DESCRIPTION:
7
+
8
+ Did you ever want to make your flay results persistent?!? Me neither,
9
+ but now you can! This flay plugin allows you to run flay across
10
+ multiple runs combining and persisting the results. This allows you to
11
+ detect plagiarism or good gem candidates across multiple projects.
12
+
13
+ == FEATURES/PROBLEMS:
14
+
15
+ * Adds -p flag to persist data on a file-by-file basis.
16
+ * Adds -r flag to re-run against already scanned files.
17
+ * Currently uses Marshal to persist... This begs for maglev.
18
+
19
+ == SYNOPSIS:
20
+
21
+ % flay -p some_project
22
+ % flay -p -r other_project # redo already scanned files with -r
23
+ % flay -p # just show the persisted data
24
+
25
+ == REQUIREMENTS:
26
+
27
+ * flay 2.1+
28
+
29
+ == INSTALL:
30
+
31
+ * sudo gem install flay-persistence
32
+
33
+ == LICENSE:
34
+
35
+ (The MIT License)
36
+
37
+ Copyright (c) Ryan Davis, seattle.rb
38
+
39
+ Permission is hereby granted, free of charge, to any person obtaining
40
+ a copy of this software and associated documentation files (the
41
+ 'Software'), to deal in the Software without restriction, including
42
+ without limitation the rights to use, copy, modify, merge, publish,
43
+ distribute, sublicense, and/or sell copies of the Software, and to
44
+ permit persons to whom the Software is furnished to do so, subject to
45
+ the following conditions:
46
+
47
+ The above copyright notice and this permission notice shall be
48
+ included in all copies or substantial portions of the Software.
49
+
50
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
51
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
52
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
53
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
54
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
55
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
56
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ # -*- ruby -*-
2
+
3
+ require "rubygems"
4
+ require "hoe"
5
+
6
+ Hoe.add_include_dirs "../../flay/dev/lib"
7
+
8
+ Hoe.plugin :isolate
9
+ Hoe.plugin :seattlerb
10
+
11
+ Hoe.spec "flay-persistence" do
12
+ developer "Ryan Davis", "ryand-ruby@zenspider.com"
13
+ license "MIT"
14
+
15
+ dependency "flay", "~> 2.0" # HACK: should be 2.1
16
+ dependency "RubyInline", "~> 3.12"
17
+ end
18
+
19
+ # vim: syntax=ruby
@@ -0,0 +1,87 @@
1
+ require "rubygems"
2
+ require "flay"
3
+
4
+ ##
5
+ # A simple plugin that adds persistence to flay
6
+
7
+ class Flay::Persistence
8
+ # duh
9
+ VERSION = "1.0.0"
10
+ end
11
+
12
+ class Flay # :nodoc:
13
+ def self.options_persistence op, options # :nodoc:
14
+ op.separator nil
15
+ op.separator "Persistence options:"
16
+ op.separator nil
17
+
18
+ options[:redo] = false
19
+
20
+ op.on("-r", "--redo", "Rerun a file already in the persistent db") do
21
+ options[:redo] = true
22
+ end
23
+
24
+ op.on("-p", "--persistent", "Use a stable hash and persist flay data.") do
25
+ require "stable_hash"
26
+
27
+ Sexp.send :alias_method, :old_structural_hash, :structural_hash
28
+ Sexp.send :alias_method, :structural_hash, :stable_hash
29
+ Flay.send :alias_method, :persist_process, :process
30
+ Flay.send :alias_method, :process, :persist_hashes
31
+
32
+ options[:persistent] = true
33
+ end
34
+ end
35
+
36
+ def merge_hash h # :nodoc:
37
+ h.each do |code, ary|
38
+ self.hashes[code].concat ary
39
+ end
40
+ end
41
+
42
+ ##
43
+ # Overrides +process+ when the -p command-line option is used. This
44
+ # loads up the persisted data, runs specified files individually,
45
+ # merges those options with the main flay dataset, and then
46
+ # saves the data back out.
47
+ #
48
+ # NOTE: Currently this is using Marshal because it is cheap and
49
+ # easy. I don't plan for it to stay that way because it will bog
50
+ # down. I'm hoping to get maglev sorted out so this can run on
51
+ # maglev and take advantage of the transparent multi-process
52
+ # persistence.
53
+
54
+ def persist_hashes(*args)
55
+ db_path = "flay.db"
56
+ files = {}
57
+
58
+ if File.exist? db_path then
59
+ File.open db_path, "rb" do |f|
60
+ files = Marshal.load f
61
+ end
62
+ end
63
+
64
+ args.each do |path|
65
+ next if files[path] unless option[:redo]
66
+
67
+ initialize self.option
68
+ persist_process path
69
+
70
+ files[path] = self.hashes
71
+ end
72
+
73
+ initialize self.option
74
+
75
+ files.each do |_, subhashes|
76
+ merge_hash subhashes
77
+ end
78
+ ensure
79
+ files.each do |code, hash| # strip default procs for marshal... ugh
80
+ files[code] = {}.merge(hash)
81
+ end
82
+
83
+ File.open db_path, "wb" do |f|
84
+ Marshal.dump files, f
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,107 @@
1
+ $: << "../../RubyInline/dev/lib"
2
+ require "rubygems"
3
+ require "inline"
4
+ require "sexp"
5
+
6
+ class Sexp # :nodoc:
7
+ begin
8
+ names = %w(alias and arglist args array attrasgn attrset back_ref
9
+ begin block block_pass break call case cdecl class colon2
10
+ colon3 const cvar cvasgn cvdecl defined defn defs dot2
11
+ dot3 dregx dregx_once dstr dsym dxstr ensure evstr false
12
+ flip2 flip3 for gasgn gvar hash iasgn if iter ivar lasgn
13
+ lit lvar masgn match match2 match3 module next nil not
14
+ nth_ref op_asgn op_asgn1 op_asgn2 op_asgn_and op_asgn_or or
15
+ postexe redo resbody rescue retry return sclass self
16
+ splat str super svalue to_ary true undef until valias
17
+ when while xstr yield zsuper)
18
+
19
+ ##
20
+ # All ruby_parser nodes in an index hash. Used by jenkins algorithm.
21
+
22
+ NODE_NAMES = Hash[names.each_with_index.map {|n, i| [n.to_sym, i] }]
23
+
24
+ ##
25
+ # Calculate the jenkins hash and memoize it.
26
+
27
+ def stable_hash
28
+ @stable_hash ||= self._stable_hash
29
+ end
30
+
31
+ inline :C do |b|
32
+ raise CompilationError if ENV["PURE_RUBY"]
33
+
34
+ b.alias_type_converter "unsigned int", "uint32_t"
35
+ b.map_ruby_const "Sexp", "NODE_NAMES"
36
+ b.add_id :grep
37
+
38
+ b.prefix <<-C
39
+ static uint32_t jenkins(VALUE sexp) {
40
+ // http://www.burtleburtle.net/bob/hash/doobs.html
41
+ // http://en.wikipedia.org/wiki/Jenkins_hash_function
42
+
43
+ uint32_t hash = 0;
44
+ VALUE n;
45
+ size_t max, i;
46
+
47
+ n = rb_hash_lookup(cNODE_NAMES, rb_ary_entry(sexp, 0));
48
+
49
+ if (! RTEST(n)) {
50
+ rb_p(sexp);
51
+ rb_raise(rb_eStandardError, "bad lookup");
52
+ }
53
+
54
+ hash += FI\X2INT(n);
55
+ hash += hash << 10;
56
+ hash ^= hash >> 6;
57
+
58
+ for (i = 0; i < RARRAY_LEN(sexp); i++) {
59
+ VALUE obj = RARRAY_PTR(sexp)[i];
60
+ if (CLASS_OF(obj) == cSexp) {
61
+ hash += jenkins(obj);
62
+ hash += hash << 10;
63
+ hash ^= hash >> 6;
64
+ }
65
+ }
66
+
67
+ hash += hash << 3;
68
+ hash ^= hash >> 11;
69
+ hash += hash << 15;
70
+
71
+ return hash;
72
+ }
73
+ C
74
+
75
+ b.c <<-C
76
+ uint32_t _stable_hash() {
77
+ return jenkins(self);
78
+ }
79
+ C
80
+ end
81
+ rescue CompilationError
82
+ MAX_INT32 = 2 ** 32 - 1 # :nodoc:
83
+
84
+ def _stable_hash # :nodoc: see above
85
+ hash = 0
86
+
87
+ n = NODE_NAMES.fetch first
88
+
89
+ hash += n & MAX_INT32
90
+ hash += hash << 10 & MAX_INT32
91
+ hash ^= hash >> 6 & MAX_INT32
92
+
93
+ each do |o|
94
+ next unless Sexp === o
95
+ hash = hash + o.stable_hash & MAX_INT32
96
+ hash = (hash + (hash << 10)) & MAX_INT32
97
+ hash = (hash ^ (hash >> 6)) & MAX_INT32
98
+ end
99
+
100
+ hash = (hash + (hash << 3)) & MAX_INT32
101
+ hash = (hash ^ (hash >> 11)) & MAX_INT32
102
+ hash = (hash + (hash << 15)) & MAX_INT32
103
+
104
+ hash
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,52 @@
1
+ require "minitest/autorun"
2
+ require "flay"
3
+ # require "flay_persistence" -- loaded by plugin system
4
+
5
+ module TestFlay; end
6
+
7
+ class TestFlay::TestPersistence < MiniTest::Unit::TestCase
8
+ def test_ARGH
9
+ persist = ENV["P"]
10
+
11
+ skip "Array#hash is buggy on 1.8" if RUBY_VERSION < "1.9" and not persist
12
+
13
+ opts = persist ? %w[-p] : []
14
+ opts = Flay.parse_options opts
15
+ flay = Flay.new opts
16
+
17
+ # from array_bare_hash_labels and proc_args_0 in pt_testcase.rb:
18
+
19
+ sexp = s(:block,
20
+ s(:hash,
21
+ s(:str),
22
+ s(:str),
23
+ s(:str),
24
+ s(:call,
25
+ s(:lit),
26
+ s(:call, s(:lit), s(:lit)),
27
+ s(:call,
28
+ s(:lit),
29
+ s(:call, s(:lit), s(:lit)),
30
+ s(:call, s(:lit), s(:lit))))),
31
+ s(:hash,
32
+ s(:str),
33
+ s(:str),
34
+ s(:str),
35
+ s(:call,
36
+ s(:lit),
37
+ s(:call, s(:lit), s(:nil), s(:lit)),
38
+ s(:lit),
39
+ s(:call,
40
+ s(:lit),
41
+ s(:call, s(:lit), s(:nil), s(:lit)),
42
+ s(:lit),
43
+ s(:call, s(:lit), s(:lit))))))
44
+
45
+ flay.process_sexp sexp
46
+
47
+ expect = [[:call], [:hash], [:hash]]
48
+ actual = flay.hashes.values.map { |ss| ss.map(&:first) }
49
+
50
+ assert_equal expect, actual.sort_by { |a| a.first.to_s }
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flay-persistence
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Ryan Davis
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain:
17
+ - |
18
+ -----BEGIN CERTIFICATE-----
19
+ MIIDPjCCAiagAwIBAgIBADANBgkqhkiG9w0BAQUFADBFMRMwEQYDVQQDDApyeWFu
20
+ ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
21
+ GRYDY29tMB4XDTA5MDM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Z
40
+ dependencies:
41
+ - !ruby/object:Gem::Dependency
42
+ name: flay
43
+ prerelease: false
44
+ requirement: &id001 !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 2
52
+ - 0
53
+ version: "2.0"
54
+ type: :runtime
55
+ version_requirements: *id001
56
+ - !ruby/object:Gem::Dependency
57
+ name: RubyInline
58
+ prerelease: false
59
+ requirement: &id002 !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ~>
63
+ - !ruby/object:Gem::Version
64
+ hash: 31
65
+ segments:
66
+ - 3
67
+ - 12
68
+ version: "3.12"
69
+ type: :runtime
70
+ version_requirements: *id002
71
+ - !ruby/object:Gem::Dependency
72
+ name: minitest
73
+ prerelease: false
74
+ requirement: &id003 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ hash: 23
80
+ segments:
81
+ - 4
82
+ - 6
83
+ version: "4.6"
84
+ type: :development
85
+ version_requirements: *id003
86
+ - !ruby/object:Gem::Dependency
87
+ name: rdoc
88
+ prerelease: false
89
+ requirement: &id004 !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ hash: 19
95
+ segments:
96
+ - 3
97
+ - 10
98
+ version: "3.10"
99
+ type: :development
100
+ version_requirements: *id004
101
+ - !ruby/object:Gem::Dependency
102
+ name: hoe
103
+ prerelease: false
104
+ requirement: &id005 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ hash: 13
110
+ segments:
111
+ - 3
112
+ - 5
113
+ version: "3.5"
114
+ type: :development
115
+ version_requirements: *id005
116
+ description: |-
117
+ Did you ever want to make your flay results persistent?!? Me neither,
118
+ but now you can! This flay plugin allows you to run flay across
119
+ multiple runs combining and persisting the results. This allows you to
120
+ detect plagiarism or good gem candidates across multiple projects.
121
+ email:
122
+ - ryand-ruby@zenspider.com
123
+ executables: []
124
+
125
+ extensions: []
126
+
127
+ extra_rdoc_files:
128
+ - History.txt
129
+ - Manifest.txt
130
+ - README.txt
131
+ files:
132
+ - .autotest
133
+ - History.txt
134
+ - Manifest.txt
135
+ - README.txt
136
+ - Rakefile
137
+ - lib/flay_persistence.rb
138
+ - lib/stable_hash.rb
139
+ - test/flay/test_persistence.rb
140
+ - .gemtest
141
+ homepage: https://github.com/seattlerb/flay-persistence
142
+ licenses:
143
+ - MIT
144
+ post_install_message:
145
+ rdoc_options:
146
+ - --main
147
+ - README.txt
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ hash: 3
165
+ segments:
166
+ - 0
167
+ version: "0"
168
+ requirements: []
169
+
170
+ rubyforge_project: flay-persistence
171
+ rubygems_version: 1.8.25
172
+ signing_key:
173
+ specification_version: 3
174
+ summary: Did you ever want to make your flay results persistent?!? Me neither, but now you can! This flay plugin allows you to run flay across multiple runs combining and persisting the results
175
+ test_files:
176
+ - test/flay/test_persistence.rb
Binary file