pdd 0.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/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ Gemfile.lock
2
+ .idea/
3
+ *.gem
4
+ .bundle/
5
+ .DS_Store
6
+ rdoc/
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ MethodLength:
2
+ Max: 30
data/.rultor.yml ADDED
@@ -0,0 +1,15 @@
1
+ assets:
2
+ rubygems.yml: "yegor256/home#assets/rubygems.yml"
3
+
4
+ release:
5
+ script:
6
+ - "sudo apt-get update"
7
+ - "sudo apt-get install -y --fix-missing libmagic1 libmagic-dev"
8
+ - "sudo bundle install"
9
+ - "rake"
10
+ - "rm -rf *.gem"
11
+ - "sed -i \"s/1\\.0\\.snapshot/${tag}/g\" pdd.gemspec"
12
+ - "gem build pdd.gemspec"
13
+ - "chmod 0600 ../rubygems.yml"
14
+ - "gem push *.gem --config-file ../rubygems.yml"
15
+
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ cache: bundler
3
+ branches:
4
+ only:
5
+ - master
6
+ install:
7
+ - sudo apt-get update
8
+ - travis_retry sudo apt-get install -y --fix-missing libmagic1 libmagic-dev
9
+ - travis_retry bundle install
10
+ script:
11
+ - rake
12
+
data/Gemfile ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ #
3
+ # Copyright (c) 2014 TechnoPark Corp.
4
+ # Copyright (c) 2014 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ source 'https://rubygems.org'
25
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2014 TechnoPark Corp.
4
+ Copyright (c) 2014 Yegor Bugayenko
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the 'Software'), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ [![Build Status](https://travis-ci.org/teamed/pdd.svg)](https://travis-ci.org/teamed/pdd)
2
+ [![Gem Version](https://badge.fury.io/rb/pdd.svg)](http://badge.fury.io/rb/pdd)
3
+ [![Dependency Status](https://gemnasium.com/teamed/pdd.svg)](https://gemnasium.com/teamed/pdd)
4
+ [![Code Climate](http://img.shields.io/codeclimate/github/teamed/pdd.svg)](https://codeclimate.com/github/teamed/pdd)
5
+
6
+ Install it first:
7
+
8
+ ```bash
9
+ gem install pdd
10
+ ```
11
+
12
+ Run it locally:
13
+
14
+ ```bash
15
+ pdd
16
+ ```
data/Rakefile ADDED
@@ -0,0 +1,68 @@
1
+ # coding: utf-8
2
+ #
3
+ # Copyright (c) 2014 TechnoPark Corp.
4
+ # Copyright (c) 2014 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'rubygems'
25
+ require 'rake'
26
+ require 'rdoc'
27
+
28
+ def name
29
+ @name ||= File.basename(Dir['*.gemspec'].first, '.*')
30
+ end
31
+
32
+ def version
33
+ Gem::Specification.load(Dir['*.gemspec'].first).version
34
+ end
35
+
36
+ task default: [:test, :features, :rubocop]
37
+
38
+ require 'rake/testtask'
39
+ desc 'Run all unit tests'
40
+ Rake::TestTask.new(:test) do |test|
41
+ test.libs << 'lib' << 'test'
42
+ test.pattern = 'test/**/test_*.rb'
43
+ test.verbose = true
44
+ end
45
+
46
+ require 'rdoc/task'
47
+ desc 'Build RDoc documentation'
48
+ Rake::RDocTask.new do |rdoc|
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "#{name} #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
54
+
55
+ require 'rubocop/rake_task'
56
+ desc 'Run RuboCop on all directories'
57
+ RuboCop::RakeTask.new(:rubocop) do |task|
58
+ task.fail_on_error = true
59
+ task.requires << 'rubocop-rspec'
60
+ end
61
+
62
+ require 'cucumber/rake/task'
63
+ Cucumber::Rake::Task.new(:features) do |t|
64
+ t.profile = 'travis'
65
+ end
66
+ Cucumber::Rake::Task.new(:"features:html") do |t|
67
+ t.profile = 'html_report'
68
+ end
data/bin/pdd ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ #
4
+ # Copyright (c) 2014 TechnoPark Corp.
5
+ # Copyright (c) 2014 Yegor Bugayenko
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the 'Software'), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ STDOUT.sync = true
26
+
27
+ require 'pdd'
28
+
29
+ puts PDD::Base.new(Dir.pwd).xml
data/cucumber.yml ADDED
@@ -0,0 +1,3 @@
1
+ default: --format pretty
2
+ travis: --format progress
3
+ html_report: --format progress --format html --out=features_report.html
@@ -0,0 +1,50 @@
1
+ Feature: Parsing
2
+ As a source code writer I want to be able to
3
+ collect all puzzles from all my text files and
4
+ present them in XML format
5
+
6
+ Scenario: Simple puzzles collecting
7
+ Given I have a "Sample.java" file with content:
8
+ """
9
+ public class Main {
10
+ /**
11
+ * @todo #13 Let's do it later, dude
12
+ * or maybe even never :)
13
+ */
14
+ public void main(String[] args) {
15
+ // later
16
+ }
17
+ }
18
+ """
19
+ When I run pdd
20
+ Then XML matches "/puzzles[count(puzzle)=1]"
21
+ And XML matches "//puzzle[file='Sample.java']"
22
+ And XML matches "//puzzle[ticket='13']"
23
+ And XML matches "//puzzle[lines='3-4']"
24
+ And XML matches "//puzzle[starts-with(body,'Let')]"
25
+ And XML matches "//puzzle[role='IMP']"
26
+ And XML matches "//puzzle[estimate='0']"
27
+
28
+ Scenario: Multiple puzzles in one file
29
+ Given I have a "test/a/b/c/Sample.java" file with content:
30
+ """
31
+ public class Main {
32
+ /**
33
+ * @todo #13 This one later
34
+ * @todo #ABC-67:15min And this one ever later
35
+ * @todo #F-78-3:2h/DEV This is for a developer
36
+ * who will join us later
37
+ */
38
+ public void main(String[] args) {
39
+ // later
40
+ }
41
+ }
42
+ """
43
+ When I run pdd
44
+ Then XML matches "/puzzles[count(puzzle)=3]"
45
+ And XML matches "//puzzle[ticket='13' and lines='3']"
46
+ And XML matches "//puzzle[ticket='13' and body='This one later']"
47
+ And XML matches "//puzzle[ticket='ABC-67' and lines='4']"
48
+ And XML matches "//puzzle[ticket='F-78-3' and lines='5-6']"
49
+ And XML matches "//puzzle[ticket='ABC-67' and estimate='15']"
50
+ And XML matches "//puzzle[ticket='F-78-3' and estimate='120']"
@@ -0,0 +1,51 @@
1
+ # coding: utf-8
2
+ #
3
+ # Copyright (c) 2014 TechnoPark Corp.
4
+ # Copyright (c) 2014 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'pdd'
25
+ require 'nokogiri'
26
+ require 'tmpdir'
27
+
28
+ Before do
29
+ @dir = Dir.mktmpdir('test')
30
+ FileUtils.mkdir_p(@dir) unless File.exist?(@dir)
31
+ Dir.chdir(@dir)
32
+ end
33
+
34
+ After do
35
+ FileUtils.rm_rf(@dir) if File.exist?(@dir)
36
+ end
37
+
38
+ Given(/^I have a "([^"]*)" file with content:$/) do |file, text|
39
+ FileUtils.mkdir_p(File.dirname(file)) unless File.exist?(file)
40
+ File.open(file, 'w') do |f|
41
+ f.write(text)
42
+ end
43
+ end
44
+
45
+ When(/^I run pdd$/) do
46
+ @xml = Nokogiri::XML.parse(PDD::Base.new(@dir).xml)
47
+ end
48
+
49
+ Then(/^XML matches "([^"]+)"$/) do |xpath|
50
+ fail "XML doesn't match \"#{xpath}\":\n#{@xml}" if @xml.xpath(xpath).empty?
51
+ end
data/lib/pdd.rb ADDED
@@ -0,0 +1,63 @@
1
+ # coding: utf-8
2
+ #
3
+ # Copyright (c) 2014 TechnoPark Corp.
4
+ # Copyright (c) 2014 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'pdd/sources'
25
+ require 'nokogiri'
26
+
27
+ # PDD main module.
28
+ # Author:: Yegor Bugayenko (yegor@teamed.io)
29
+ # Copyright:: Copyright (c) 2014 Yegor Bugayenko
30
+ # License:: MIT
31
+ module PDD
32
+ # Code base abstraction
33
+ class Base
34
+ # Ctor.
35
+ # +dir+:: Directory with source code
36
+ def initialize(dir)
37
+ @dir = dir
38
+ end
39
+
40
+ # Generate XML.
41
+ def xml
42
+ Nokogiri::XML::Builder.new do |xml|
43
+ xml << '<?xml-stylesheet type="text/xsl" href="puzzles.xsl"?>'
44
+ xml.puzzles do
45
+ Sources.new(@dir).fetch.each do |source|
46
+ source.puzzles.each { |puzzle| render puzzle, xml }
47
+ end
48
+ end
49
+ end.to_xml
50
+ end
51
+
52
+ private
53
+
54
+ def render(puzzle, xml)
55
+ props = puzzle.props
56
+ xml.puzzle do
57
+ props.map do |k, v|
58
+ xml.send(:"#{k}", v)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
data/lib/pdd/puzzle.rb ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ #
3
+ # Copyright (c) 2014 TechnoPark Corp.
4
+ # Copyright (c) 2014 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ module PDD
25
+ # Puzzle.
26
+ class Puzzle
27
+ # Ctor.
28
+ # +props+:: Properties
29
+ def initialize(props)
30
+ @props = props
31
+ end
32
+ attr_reader :props
33
+ end
34
+ end
data/lib/pdd/source.rb ADDED
@@ -0,0 +1,89 @@
1
+ # coding: utf-8
2
+ #
3
+ # Copyright (c) 2014 TechnoPark Corp.
4
+ # Copyright (c) 2014 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'pdd/puzzle'
25
+
26
+ module PDD
27
+ # Source.
28
+ class Source
29
+ # Ctor.
30
+ # +file+:: Absolute file name with source code
31
+ # +path+:: Path to show (without full file name)
32
+ def initialize(file, path)
33
+ @file = file
34
+ @path = path
35
+ end
36
+
37
+ # Fetch all puzzles.
38
+ def puzzles
39
+ re = /(.*(?:^|\s))@todo\s+#([\w\-\.:\/]+)\s+(.+)/
40
+ puzzles = []
41
+ lines = File.readlines(@file)
42
+ lines.each_with_index do |line, idx|
43
+ re.match(line) do |match|
44
+ prefix = match[1] + ' '
45
+ total = 0
46
+ body = (match[3] + ' ' + lines.drop(idx + 1)
47
+ .take_while { |txt| txt.start_with?(prefix) }
48
+ .map { |txt| txt[prefix.length, txt.length] }
49
+ .map do |txt|
50
+ total += 1
51
+ txt
52
+ end
53
+ .join(' '))
54
+ .gsub(/\s+/, ' ')
55
+ .strip
56
+ puzzles << Puzzle.new(
57
+ marker(match[2]).merge(
58
+ lines: total > 0 ? "#{idx + 1}-#{idx + total + 1}" : idx + 1,
59
+ body: body,
60
+ file: @path
61
+ )
62
+ )
63
+ end
64
+ end
65
+ puzzles
66
+ end
67
+
68
+ private
69
+
70
+ # Parse a marker.
71
+ def marker(text)
72
+ re = /([\w\d\-\.]+)(?::(\d+)(?:(m|h)[a-z]*)?)?(?:\/([A-Z]+))?/
73
+ match = re.match(text)
74
+ fail "invalid puzzle marker: #{text}" if match.nil?
75
+ {
76
+ ticket: match[1],
77
+ estimate: minutes(match[2], match[3]),
78
+ role: match[4].nil? ? 'IMP' : match[4]
79
+ }
80
+ end
81
+
82
+ # Parse minutes.
83
+ def minutes(num, units)
84
+ min = num.nil? ? 0 : Integer(num)
85
+ min *= 60 if !units.nil? && units.start_with?('h')
86
+ min
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+ #
3
+ # Copyright (c) 2014 TechnoPark Corp.
4
+ # Copyright (c) 2014 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'filemagic'
25
+ require 'pdd/source'
26
+
27
+ module PDD
28
+ # Code base abstraction
29
+ class Sources
30
+ # Ctor.
31
+ # +dir+:: Directory with source code files
32
+ def initialize(dir)
33
+ @dir = dir
34
+ @magic = FileMagic.new(FileMagic::MAGIC_MIME)
35
+ end
36
+
37
+ # Fetch all sources.
38
+ def fetch
39
+ Dir.glob(@dir + '/**/*')
40
+ .select { |f| @magic.file(f) =~ /^text\// }
41
+ .map do |file|
42
+ Source.new(file, file[@dir.length + 1, file.length])
43
+ end
44
+ end
45
+ end
46
+ end
data/pdd.gemspec ADDED
@@ -0,0 +1,52 @@
1
+ # coding: utf-8
2
+ #
3
+ # Copyright (c) 2014 TechnoPark Corp.
4
+ # Copyright (c) 2014 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ Gem::Specification.new do |s|
25
+ s.specification_version = 2 if s.respond_to? :specification_version=
26
+ if s.respond_to? :required_rubygems_version=
27
+ s.required_rubygems_version = Gem::Requirement.new('>= 0')
28
+ end
29
+ s.rubygems_version = '2.2.2'
30
+ s.required_ruby_version = '>= 1.9.3'
31
+ s.name = 'pdd'
32
+ s.version = '0.1'
33
+ s.license = 'MIT'
34
+ s.summary = 'Puzzle Driven Development collector'
35
+ s.description = 'Collects puzzles from source code base'
36
+ s.authors = ['Yegor Bugayenko']
37
+ s.email = 'yegor@teamed.io'
38
+ s.homepage = 'http://github.com/teamed/pdd'
39
+ s.files = `git ls-files`.split($RS)
40
+ s.executables = s.files.grep(/{^bin\/}/) { |f| File.basename(f) }
41
+ s.test_files = s.files.grep(/{^(test|spec|features)\/}/)
42
+ s.rdoc_options = ['--charset=UTF-8']
43
+ s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
44
+ s.add_runtime_dependency 'nokogiri', '~> 1.6', '>= 1.6.3.1'
45
+ s.add_runtime_dependency 'ruby-filemagic', '~> 0.6', '>= 0.6.0'
46
+ s.add_development_dependency 'rake', '~> 10.1'
47
+ s.add_development_dependency 'rdoc', '~> 3.11'
48
+ s.add_development_dependency 'cucumber', '1.3.11'
49
+ s.add_development_dependency 'minitest', '~> 5.4', '>= 5.4.0'
50
+ s.add_development_dependency 'rubocop', '~> 0.24', '>= 0.24.1'
51
+ s.add_development_dependency 'rubocop-rspec', '~> 1.1', '>= 1.1.0'
52
+ end
data/test/test_pdd.rb ADDED
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ #
3
+ # Copyright (c) 2014 TechnoPark Corp.
4
+ # Copyright (c) 2014 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'minitest/autorun'
25
+ require 'nokogiri'
26
+ require 'pdd'
27
+ require 'tmpdir'
28
+
29
+ # PDD main module test.
30
+ # Author:: Yegor Bugayenko (yegor@teamed.io)
31
+ # Copyright:: Copyright (c) 2014 Yegor Bugayenko
32
+ # License:: MIT
33
+ class TestPDD < Minitest::Test
34
+ def test_basic
35
+ Dir.mktmpdir 'test' do |dir|
36
+ File.write(File.join(dir, 'a.txt'), '@todo #55 hello!')
37
+ xml = Nokogiri::XML::Document.parse(PDD::Base.new(dir).xml)
38
+ assert_equal xml.xpath('/puzzles/puzzle[file="a.txt"]').size, 1
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,54 @@
1
+ # coding: utf-8
2
+ #
3
+ # Copyright (c) 2014 TechnoPark Corp.
4
+ # Copyright (c) 2014 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'minitest/autorun'
25
+ require 'pdd/sources'
26
+ require 'tmpdir'
27
+
28
+ # Source test.
29
+ # Author:: Yegor Bugayenko (yegor@teamed.io)
30
+ # Copyright:: Copyright (c) 2014 Yegor Bugayenko
31
+ # License:: MIT
32
+ class TestSources < Minitest::Test
33
+ def test_parsing
34
+ Dir.mktmpdir 'test' do |dir|
35
+ file = File.join(dir, 'a.txt')
36
+ File.write(
37
+ file,
38
+ '
39
+ * @todo #44 hello,
40
+ * how are you doing?
41
+ Something else
42
+ ~~ @todo #ABC-3 this is another puzzle
43
+ ~~ and it also has to work
44
+ '
45
+ )
46
+ list = PDD::Source.new(file, 'hey').puzzles
47
+ assert_equal 2, list.size
48
+ puzzle = list.first
49
+ assert_equal '2-3', puzzle.props[:lines]
50
+ assert_equal 'hello, how are you doing?', puzzle.props[:body]
51
+ assert_equal '44', puzzle.props[:ticket]
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,51 @@
1
+ # coding: utf-8
2
+ #
3
+ # Copyright (c) 2014 TechnoPark Corp.
4
+ # Copyright (c) 2014 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'minitest/autorun'
25
+ require 'pdd/sources'
26
+ require 'tmpdir'
27
+
28
+ # Sources test.
29
+ # Author:: Yegor Bugayenko (yegor@teamed.io)
30
+ # Copyright:: Copyright (c) 2014 Yegor Bugayenko
31
+ # License:: MIT
32
+ class TestSources < Minitest::Test
33
+ def test_iterator
34
+ Dir.mktmpdir 'test' do |dir|
35
+ File.write(File.join(dir, 'a.txt'), '@todo hello!')
36
+ Dir.mkdir(File.join(dir, 'b'))
37
+ File.write(File.join(dir, 'b/c.txt'), 'hello, again')
38
+ list = PDD::Sources.new(dir).fetch
39
+ assert_equal 2, list.size
40
+ end
41
+ end
42
+
43
+ def test_ignores_binary_files
44
+ Dir.mktmpdir 'test' do |dir|
45
+ File.write(File.join(dir, 'c'), 'how are you?')
46
+ File.write(File.join(dir, 'd.png'), '')
47
+ list = PDD::Sources.new(dir).fetch
48
+ assert_equal 1, list.size
49
+ end
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,226 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pdd
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yegor Bugayenko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: 1.6.3.1
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.6'
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: 1.6.3.1
36
+ - !ruby/object:Gem::Dependency
37
+ name: ruby-filemagic
38
+ requirement: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '0.6'
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.6.0
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.6'
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: 0.6.0
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
60
+ requirement: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '10.1'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ version: '10.1'
74
+ - !ruby/object:Gem::Dependency
75
+ name: rdoc
76
+ requirement: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: '3.11'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '3.11'
90
+ - !ruby/object:Gem::Dependency
91
+ name: cucumber
92
+ requirement: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - '='
96
+ - !ruby/object:Gem::Version
97
+ version: 1.3.11
98
+ type: :development
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - '='
104
+ - !ruby/object:Gem::Version
105
+ version: 1.3.11
106
+ - !ruby/object:Gem::Dependency
107
+ name: minitest
108
+ requirement: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ~>
112
+ - !ruby/object:Gem::Version
113
+ version: '5.4'
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: 5.4.0
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '5.4'
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: 5.4.0
128
+ - !ruby/object:Gem::Dependency
129
+ name: rubocop
130
+ requirement: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ~>
134
+ - !ruby/object:Gem::Version
135
+ version: '0.24'
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: 0.24.1
139
+ type: :development
140
+ prerelease: false
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ~>
145
+ - !ruby/object:Gem::Version
146
+ version: '0.24'
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: 0.24.1
150
+ - !ruby/object:Gem::Dependency
151
+ name: rubocop-rspec
152
+ requirement: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: '1.1'
158
+ - - ! '>='
159
+ - !ruby/object:Gem::Version
160
+ version: 1.1.0
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ none: false
165
+ requirements:
166
+ - - ~>
167
+ - !ruby/object:Gem::Version
168
+ version: '1.1'
169
+ - - ! '>='
170
+ - !ruby/object:Gem::Version
171
+ version: 1.1.0
172
+ description: Collects puzzles from source code base
173
+ email: yegor@teamed.io
174
+ executables: []
175
+ extensions: []
176
+ extra_rdoc_files:
177
+ - README.md
178
+ - LICENSE.txt
179
+ files:
180
+ - .gitignore
181
+ - .rubocop.yml
182
+ - .rultor.yml
183
+ - .travis.yml
184
+ - Gemfile
185
+ - LICENSE.txt
186
+ - README.md
187
+ - Rakefile
188
+ - bin/pdd
189
+ - cucumber.yml
190
+ - features/parsing.feature
191
+ - features/step_definitions/steps.rb
192
+ - lib/pdd.rb
193
+ - lib/pdd/puzzle.rb
194
+ - lib/pdd/source.rb
195
+ - lib/pdd/sources.rb
196
+ - pdd.gemspec
197
+ - test/test_pdd.rb
198
+ - test/test_source.rb
199
+ - test/test_sources.rb
200
+ homepage: http://github.com/teamed/pdd
201
+ licenses:
202
+ - MIT
203
+ post_install_message:
204
+ rdoc_options:
205
+ - --charset=UTF-8
206
+ require_paths:
207
+ - lib
208
+ required_ruby_version: !ruby/object:Gem::Requirement
209
+ none: false
210
+ requirements:
211
+ - - ! '>='
212
+ - !ruby/object:Gem::Version
213
+ version: 1.9.3
214
+ required_rubygems_version: !ruby/object:Gem::Requirement
215
+ none: false
216
+ requirements:
217
+ - - ! '>='
218
+ - !ruby/object:Gem::Version
219
+ version: '0'
220
+ requirements: []
221
+ rubyforge_project:
222
+ rubygems_version: 1.8.23
223
+ signing_key:
224
+ specification_version: 2
225
+ summary: Puzzle Driven Development collector
226
+ test_files: []