metado 0.1.0

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: 7635052f7b0458d60892bf8857e87cf5ec2e610f89ab8e4fda525a7dd01642ff
4
+ data.tar.gz: 3d3352f0b937ce94ed6456eb108e337993e6f94c5116e815cdb5e8c6e190db99
5
+ SHA512:
6
+ metadata.gz: b9573425f80f240937eae337707cf21cb0e688eccdb3ee14b23268a73cd689454448e2e87738d8fdeab563f4ad12dec4619d5389c841fc630f788320211cb6aa
7
+ data.tar.gz: ab019ca4c62dc76b5071b6fef9abce45743d025175d9416bbc2906fa846b195aa1ba6543a62d15643946fae7ab86231577821456a8bdb45669e05bf875a91083
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.0
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.10
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ metado (0.1.0)
5
+ tomlrb
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ minitest (5.14.4)
12
+ parallel (1.20.1)
13
+ parser (3.0.0.0)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.0.0)
16
+ rake (13.0.3)
17
+ regexp_parser (2.1.1)
18
+ rexml (3.2.4)
19
+ rubocop (1.11.0)
20
+ parallel (~> 1.10)
21
+ parser (>= 3.0.0.0)
22
+ rainbow (>= 2.2.2, < 4.0)
23
+ regexp_parser (>= 1.8, < 3.0)
24
+ rexml
25
+ rubocop-ast (>= 1.2.0, < 2.0)
26
+ ruby-progressbar (~> 1.7)
27
+ unicode-display_width (>= 1.4.0, < 3.0)
28
+ rubocop-ast (1.4.1)
29
+ parser (>= 2.7.1.5)
30
+ rubocop-performance (1.10.1)
31
+ rubocop (>= 0.90.0, < 2.0)
32
+ rubocop-ast (>= 0.4.0)
33
+ ruby-progressbar (1.11.0)
34
+ standard (1.0.2)
35
+ rubocop (= 1.11.0)
36
+ rubocop-performance (= 1.10.1)
37
+ tomlrb (2.0.1)
38
+ unicode-display_width (2.0.0)
39
+
40
+ PLATFORMS
41
+ arm64-darwin-20
42
+
43
+ DEPENDENCIES
44
+ metado!
45
+ minitest (~> 5.0)
46
+ rake (~> 13.0)
47
+ standard (~> 1.0.2)
48
+
49
+ BUNDLED WITH
50
+ 2.2.10
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Paul Samuels
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,155 @@
1
+ `Metado` is a tool for adding metadata to your TODOs.
2
+
3
+ ## Idea
4
+
5
+ Add structure to TODOs to make it so that you can query them across a codebase.
6
+
7
+ This tool proposes a simple markup and provides a command line tool to parse it into JSON.
8
+ This leaves the user free to do whatever filtering they desire in their favourite language.
9
+
10
+ ## Syntax rules
11
+
12
+ A metado is formed from consecutive single line comments and looks like this in a C based language:
13
+
14
+ ```
15
+ // METADO: Remove this toggle before release
16
+ // | This feature toggle should be removed with the release of Feature X
17
+ // > fixVersion = "FeatureX"
18
+ ```
19
+
20
+ - The first line denotes a metado with the token `METADO:` and the rest of the line acts as the metado's title.
21
+ - Any subsequent lines starting with a pipe ("|") create a longer form description for the metado.
22
+ - Any subsequent lines starting with a greater than operator (">") form the data portion of the metado and are parsed using TOML.
23
+
24
+ Running the tool on this readme would result in this output:
25
+
26
+ ```
27
+ ➜ metado path/to/readme/dir | jq .
28
+ [
29
+ {
30
+ "file": "path/to/readme/dir/README.md",
31
+ "line_number": 0,
32
+ "title": "Remove this toggle before release",
33
+ "body": "This feature toggle should be removed with the release of Feature X",
34
+ "data": {
35
+ "fixVersion": "FeatureX"
36
+ }
37
+ }
38
+ ]
39
+ ```
40
+
41
+ ## Example usage
42
+
43
+ Given the following metados in our source code:
44
+
45
+ ```
46
+ // METADO: Remove this toggle before release
47
+ // | This feature toggle should be removed with the release of Feature X
48
+ // > fixVersion = "FeatureX"
49
+
50
+ // METADO: Spike implementation
51
+ // | This is really inefficient and could be simplified.
52
+ // > tags = ["performance", "spike"]
53
+
54
+ // METADO: This could do with a cache
55
+ // > tags = ["performance"]
56
+ // > fixVersion = "FeatureX"
57
+ ```
58
+
59
+ If we wanted to check we have no work left to do before releasing "FeatureX" we could run the following query:
60
+
61
+ ```
62
+ ➜ metado Sources | jq 'map(select(.data.fixVersion == "FeatureX"))'
63
+ {
64
+ "file": "Example.swift",
65
+ "line_number": 27,
66
+ "title": "Remove this toggle before release",
67
+ "body": "This feature toggle should be removed with the release of Feature X",
68
+ "data": {
69
+ "fixVersion": "FeatureX"
70
+ }
71
+ }
72
+ {
73
+ "file": "Example.swift",
74
+ "line_number": 16,
75
+ "title": "This could do with a cache",
76
+ "body": "",
77
+ "data": {
78
+ "tags": [
79
+ "performance"
80
+ ],
81
+ "fixVersion": "FeatureX"
82
+ }
83
+ }
84
+ ```
85
+
86
+ If we wanted to find any metados that have been tagged as "performance" we could run the following query:
87
+
88
+ ```
89
+ ➜ metado Sources | jq 'map(select(.data.tags | index("performance")))'
90
+ [
91
+ {
92
+ "file": "Example.swift",
93
+ "line_number": 12,
94
+ "title": "Spike implementation",
95
+ "body": "This is really inefficient and could be simplified.",
96
+ "data": {
97
+ "tags": [
98
+ "performance",
99
+ "spike"
100
+ ]
101
+ }
102
+ },
103
+ {
104
+ "file": "Example.swift",
105
+ "line_number": 16,
106
+ "title": "This could do with a cache",
107
+ "body": "",
108
+ "data": {
109
+ "tags": [
110
+ "performance"
111
+ ],
112
+ "fixVersion": "FeatureX"
113
+ }
114
+ }
115
+ ]
116
+ ```
117
+
118
+ The key thing is that the metado tool outputs JSON so the filtering can be written in any language - the examples above use the `jq` command line tool.
119
+ Once the data is filtered the results could be used to notify people, fail CI builds or whatever could be useful for your project.
120
+
121
+ ## Installation
122
+
123
+ Add this line to your application's Gemfile:
124
+
125
+ ```ruby
126
+ gem 'metado'
127
+ ```
128
+
129
+ And then execute:
130
+
131
+ $ bundle install
132
+
133
+ Or install it yourself as:
134
+
135
+ $ gem install metado
136
+
137
+ ## Usage
138
+
139
+ ```
140
+ Usage: metado SOURCE_DIR
141
+ ```
142
+
143
+ ## Development
144
+
145
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
146
+
147
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
148
+
149
+ ## Contributing
150
+
151
+ Bug reports and pull requests are welcome on GitHub at https://github.com/paulsamuels/metado.
152
+
153
+ ## License
154
+
155
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+ require "standard/rake"
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << "spec"
9
+ t.libs << "lib"
10
+ t.test_files = FileList["spec/**/*_spec.rb"]
11
+ end
12
+
13
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "metado"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/metado ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "metado/cli"
4
+
5
+ Metado::CLI.start
data/lib/metado.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "metado/version"
4
+
5
+ module Metado
6
+ class Error < StandardError; end
7
+ end
data/lib/metado/cli.rb ADDED
@@ -0,0 +1,23 @@
1
+ require_relative "parser/file"
2
+ require_relative "parser/metado"
3
+
4
+ require "json"
5
+
6
+ module Metado
7
+ class CLI
8
+ def self.start
9
+ unless (dir = ARGV.first)
10
+ puts "Usage: metado SOURCE_DIR"
11
+ exit 1
12
+ end
13
+
14
+ result = Dir["#{dir}/**/*"].flat_map do |file|
15
+ next unless File.file?(file)
16
+
17
+ Parser::File.comments(file).map(&Parser::Metado.method(:parse)).flatten.map(&:to_h)
18
+ end.compact
19
+
20
+ puts JSON.generate result
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ require_relative "../type/comment"
2
+
3
+ module Metado
4
+ module Parser
5
+ module File
6
+ class << self
7
+ def comments file
8
+ regex = single_line_comment_regex(file)
9
+
10
+ ::File.readlines(file).each_with_index.reduce([[], nil]) { |(comments, current_comment), (line, index)|
11
+ if (line = line[regex, 1])
12
+ (current_comment ||= Type::Comment.new(file, index + 1, []).tap(&comments.method(:push))).body << line
13
+ else
14
+ current_comment = nil
15
+ end
16
+
17
+ [comments, current_comment]
18
+ }.first
19
+ end
20
+
21
+ private
22
+
23
+ def single_line_comment_regex file
24
+ sentinel = case ::File.extname file
25
+ when ".py", ".rb", ".sh"
26
+ "#"
27
+ when ".hs"
28
+ "--"
29
+ else
30
+ "//"
31
+ end
32
+
33
+ %r{^\s*#{sentinel}(.*)}
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,30 @@
1
+ require "tomlrb"
2
+ require_relative "../type/node"
3
+
4
+ module Metado
5
+ module Parser
6
+ module Metado
7
+ def self.parse comment
8
+ comment.body.each_with_index.reduce([[], nil]) { |(metados, current_metado), (line, index)|
9
+ if (title = line[/^\s*METADO:\s*(.*)/, 1])
10
+ current_metado = Type::Node.new(comment.file, comment.line_number + index, title, [], []).tap(&metados.method(:push))
11
+ elsif current_metado
12
+ if (body = line[/^\s*\|\s*(.*)/, 1])
13
+ current_metado.body << body
14
+ elsif (data = line[/^\s*>\s*(.*)/, 1])
15
+ current_metado.data << data
16
+ else
17
+ current_metado = nil
18
+ end
19
+ else
20
+ current_metado = nil
21
+ end
22
+
23
+ [metados, current_metado]
24
+ }.first.map { |item|
25
+ Type::Node.new(item.file, item.line_number, item.title, item.body.join("\n"), Tomlrb.parse(item.data.join("\n")))
26
+ }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module Metado
2
+ module Type
3
+ Comment = Struct.new(:file, :line_number, :body)
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Metado
2
+ module Type
3
+ Node = Struct.new(:file, :line_number, :title, :body, :data)
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metado
4
+ VERSION = "0.1.0"
5
+ end
data/metado.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/metado/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "metado"
7
+ spec.version = Metado::VERSION
8
+ spec.authors = ["Paul Samuels"]
9
+ spec.email = ["paulio1987@gmail.com"]
10
+
11
+ spec.summary = "Supercharge your todos with metadata"
12
+ spec.homepage = "https://github.com/paulsamuels/metado"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/paulsamuels/metado"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "tomlrb"
30
+ spec.add_development_dependency "minitest", "~> 5.0"
31
+ spec.add_development_dependency "rake", "~> 13.0"
32
+ spec.add_development_dependency "standard", "~> 1.0.2"
33
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metado
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Samuels
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tomlrb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.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: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: standard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.2
69
+ description:
70
+ email:
71
+ - paulio1987@gmail.com
72
+ executables:
73
+ - metado
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".github/workflows/main.yml"
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - exe/metado
87
+ - lib/metado.rb
88
+ - lib/metado/cli.rb
89
+ - lib/metado/parser/file.rb
90
+ - lib/metado/parser/metado.rb
91
+ - lib/metado/type/comment.rb
92
+ - lib/metado/type/node.rb
93
+ - lib/metado/version.rb
94
+ - metado.gemspec
95
+ homepage: https://github.com/paulsamuels/metado
96
+ licenses:
97
+ - MIT
98
+ metadata:
99
+ homepage_uri: https://github.com/paulsamuels/metado
100
+ source_code_uri: https://github.com/paulsamuels/metado
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 2.4.0
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 3.2.3
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Supercharge your todos with metadata
120
+ test_files: []