eip_validator 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
+ SHA1:
3
+ metadata.gz: 3c7542bb149c300414664dbf78db48be22b880a3
4
+ data.tar.gz: 6aa34021d899cc4b9922f1af3d195211f3641927
5
+ SHA512:
6
+ metadata.gz: 8126eec7f3b244efc655b9a7a819cc19fde5566e5ab3c36afcbd021efb4361c5026925e711473ffdecfa3bad685a80630951882f9c8ddf6affac0904a3eab7c9
7
+ data.tar.gz: 6f0b4617e46cdb2a2b52709a849c553ba59df210fd9c41f91acade445155d2cf3d7543b10a214ef455b9158280ae3a0e9782cfd2f486c48b22980b53e0b27214
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ Gemfile.lock
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at TODO: Write your email address. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rake'
4
+ gem 'front_matter_parser'
5
+ gem 'activemodel'
6
+ group :test do
7
+ gem 'rspec'
8
+ end
9
+ gem 'pry'
10
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Makoto
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,62 @@
1
+ # EIP validator
2
+
3
+ ## Validation rules
4
+
5
+ ### Mandatory fields
6
+
7
+ - eip
8
+ - title
9
+ - author
10
+ - type
11
+ - category (conditional on type)
12
+ - status
13
+ - created
14
+
15
+ ### Optional fields
16
+
17
+ - replaces
18
+ - requires
19
+ - layer
20
+
21
+ ### Mandatory values
22
+
23
+ - `status` must be `Draft`, `Accepted`, `Final`, or `Deferred`
24
+
25
+ ## Prerequisite
26
+
27
+ - ruby
28
+
29
+ ## Setup
30
+
31
+ ```
32
+ gem install eip_validator
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ```ruby
38
+ eip_validator "FILE_NAME_WITH_WILDCARD"
39
+ ```
40
+
41
+ ### Example
42
+
43
+ ```
44
+ $eip_validator "/Users/makoto/src/EIPs/EIPS/*[0-9].md"
45
+
46
+ Warning: /Users/makoto/src/EIPs/EIPS/eip-158.md unknown attribute 'superseded-by' for EipValidator::Validator.
47
+ Warning: /Users/makoto/src/EIPs/EIPS/eip-615.md unknown attribute 'edited' for EipValidator::Validator.
48
+
49
+
50
+ total:51, valid:49, invalid:0, errors:2
51
+ statuses: [["Final", 29], ["Draft", 17], ["Accepted", 2], ["Active", 1]]
52
+ types: [["Meta", 6], ["Standards Track", 42], ["Standard Track", 1]]
53
+ categories: [[nil, 6], ["Core", 23], ["ERC", 11], ["Interface", 5], ["Networking", 4]]
54
+ layers: [[nil, 47], ["Applications", 1], ["Process", 1]]
55
+
56
+ ```
57
+
58
+ ## Running tests
59
+
60
+ ```
61
+ bundle exec rspec
62
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/eip_validator ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'eip_validator'
4
+
5
+ EipValidator::Runner.run ARGV[0]
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "eip_validator/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "eip_validator"
8
+ spec.version = EipValidator::VERSION
9
+ spec.authors = ["Makoto"]
10
+ spec.email = ["@makoto_inoue"]
11
+
12
+ spec.summary = "Small library to check if EIP doc has valid front matter"
13
+ spec.homepage = "https://makoto.github.io/me"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against " \
22
+ # "public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "bin"
29
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.16"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ end
@@ -0,0 +1,11 @@
1
+ require 'yaml'
2
+ require 'front_matter_parser'
3
+
4
+
5
+ class Loader
6
+ UNSAFE_LOADER = ->(string) { YAML.load(string) }
7
+
8
+ def self.load(file_name)
9
+ FrontMatterParser::Parser.parse_file(file_name, loader: UNSAFE_LOADER).front_matter
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'active_model'
2
+
3
+ module EipValidator
4
+ class Validator
5
+ include ActiveModel::Model
6
+ attr_accessor :eip, :title, :author, :type, :category, :status, :created, :replaces, :requires, :layer
7
+ validates_presence_of :eip, :title, :author, :type, :status, :created
8
+ validates_presence_of :category, if: Proc.new { |v| v.type == 'Standards Track' }
9
+ validates_inclusion_of :status, in: %w(Draft Active Accepted Final Deferred)
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module EipValidator
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,54 @@
1
+ require "eip_validator/version"
2
+ require 'eip_validator/loader'
3
+ require 'eip_validator/validator'
4
+
5
+ module EipValidator
6
+ class Runner
7
+ class << self
8
+ def run(dir)
9
+ num_valid = 0
10
+ num_invalid = 0
11
+ num_error = 0
12
+ total = 0
13
+ puts "\n"
14
+ statuses = []
15
+ types = []
16
+ categories = []
17
+ layers = []
18
+ Dir[dir].map do |file_name|
19
+ attributes = Loader.load(file_name)
20
+ total+=1
21
+ begin
22
+ v = Validator.new(attributes)
23
+ if v.valid?
24
+ num_valid+=1
25
+ else
26
+ num_invalid+=1
27
+ puts "#{file_name} is NOT valid:\t #{v.errors.messages}"
28
+ end
29
+ statuses.push v.status
30
+ types.push v.type
31
+ categories.push v.category
32
+ layers.push v.layer
33
+ rescue ActiveModel::UnknownAttributeError => e
34
+ puts "Warning: #{file_name} \t #{e}"
35
+ num_error+=1
36
+ end
37
+ end
38
+
39
+ puts "\n\ntotal:#{total}, valid:#{num_valid}, invalid:#{num_invalid}, errors:#{num_error}"
40
+ puts "\tstatuses: #{aggregate(statuses)}"
41
+ puts "\ttypes: #{aggregate(types)}"
42
+ puts "\tcategories: #{aggregate(categories)}"
43
+ puts "\tlayers: #{aggregate(layers)}"
44
+ raise "#{num_invalid} invalid entities" unless num_invalid == 0
45
+ end
46
+
47
+ private
48
+
49
+ def aggregate(array)
50
+ array.group_by{|k,v| k}.map{|k,v| [k,v.length]}
51
+ end
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eip_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Makoto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - "@makoto_inoue"
58
+ executables:
59
+ - eip_validator
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/eip_validator
72
+ - eip_validator.gemspec
73
+ - lib/eip_validator.rb
74
+ - lib/eip_validator/loader.rb
75
+ - lib/eip_validator/validator.rb
76
+ - lib/eip_validator/version.rb
77
+ homepage: https://makoto.github.io/me
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.5.2
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Small library to check if EIP doc has valid front matter
101
+ test_files: []