pronto-flay 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ea1296eabf8d91cc67a1c0f11f55273eabdcb23e
4
+ data.tar.gz: 2e3537e9959d7dd32e4e9bd6d06c6213b2dec180
5
+ SHA512:
6
+ metadata.gz: a766cac19a8318bbb1045f1795fbfbeab84008f3417a98bb8ec9061741891d3ed2b18392677c454b8e50c9b02d3bda7049981371817a31af56d695390fac2889
7
+ data.tar.gz: c8eb55a64114c40882943044d81619c1a7f0f8e635b363370847f6288c4aed4f83d194cd79fc0add4561a9cfb543bee3ce6cd7770245922b4809fd68195f0bae
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2013 Mindaugas Mozūras
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # pronto-flay
2
+
3
+ [![Code Climate](https://codeclimate.com/github/mmozuras/pronto-flay.png)](https://codeclimate.com/github/mmozuras/pronto-flay)
4
+ [![Build Status](https://travis-ci.org/mmozuras/pronto-flay.png)](https://travis-ci.org/mmozuras/pronto-flay)
5
+ [![Dependency Status](https://gemnasium.com/mmozuras/pronto-flay.png)](https://gemnasium.com/mmozuras/pronto-flay)
@@ -0,0 +1,83 @@
1
+ require 'pronto'
2
+ require 'flay'
3
+
4
+ module Pronto
5
+ class Flay < Runner
6
+ def initialize
7
+ @flay = ::Flay.new
8
+ end
9
+
10
+ def run(patches)
11
+ return [] unless patches
12
+
13
+ ruby_patches = patches.select { |patch| patch.additions > 0 }
14
+ .select { |patch| ruby_file?(patch.new_file_full_path) }
15
+
16
+ files = ruby_patches.map { |patch| File.new(patch.new_file_full_path) }
17
+
18
+ if files.any?
19
+ @flay.process(*files)
20
+ @flay.analyze
21
+ messages_for(ruby_patches)
22
+ else
23
+ []
24
+ end
25
+ end
26
+
27
+ def messages_for(ruby_patches)
28
+ nodes.map do |node|
29
+ patch = patch_for_node(ruby_patches, node)
30
+
31
+ line = patch.added_lines.select do |added_line|
32
+ added_line.new_lineno == node.line
33
+ end.first
34
+
35
+ new_message(line, node) if line
36
+ end.flatten.compact
37
+ end
38
+
39
+ def patch_for_node(ruby_patches, node)
40
+ ruby_patches.select do |patch|
41
+ patch.new_file_full_path.to_s == node.file.path
42
+ end.first
43
+ end
44
+
45
+ def new_message(line, node)
46
+ hash = node.structural_hash
47
+ Message.new(line.patch.delta.new_file[:path], line, level(hash), message(hash))
48
+ end
49
+
50
+ def level(hash)
51
+ same?(hash) ? :error : :warning
52
+ end
53
+
54
+ def same?(hash)
55
+ @flay.identical[hash]
56
+ end
57
+
58
+ def message(hash)
59
+ match = same?(hash) ? 'Identical' : 'Similar'
60
+ location = nodes_for(hash).map do |node|
61
+ "#{File.basename(node.file.path)}:#{node.line}"
62
+ end
63
+
64
+ "#{match} code found in #{location.join(', ')}"
65
+ end
66
+
67
+ def nodes_for(hash)
68
+ @flay.hashes[hash]
69
+ end
70
+
71
+ def nodes
72
+ result = []
73
+ masses.each do |mass|
74
+ nodes_for(mass.first).each { |node| result << node }
75
+ end
76
+ result
77
+ end
78
+
79
+ def masses
80
+ Array(@flay.masses)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,5 @@
1
+ module Pronto
2
+ module FlayVersion
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pronto-flay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mindaugas Mozūras
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pronto
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: flay
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.4.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.4.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 10.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 10.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.0
69
+ description: pronto-flay
70
+ email: mindaugas.mozuras@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - lib/pronto/flay/version.rb
76
+ - lib/pronto/flay.rb
77
+ - LICENSE
78
+ - README.md
79
+ homepage: http://github.org/mmozuras/pronto-flay
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.6
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.0.7
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: pronto-flay
103
+ test_files: []
104
+ has_rdoc: