ramlstyle 0.2.3

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: d1b112906842c3a5ec171c0bf8c19b0ce3b222b8
4
+ data.tar.gz: c8965a05a9a1b4d13a79902f028dc3eee3cad339
5
+ SHA512:
6
+ metadata.gz: 5688b30823f76bb2fab1a99edd109ff311d51043833676d60748e0bb489f6194c9935e3a03ed7c5ac733a8f1508d3269aff013993d561bd23b10e288dc09dc23
7
+ data.tar.gz: dcf1ed3540a59299e2f1cbf2ad4ac902cce2c5e837b717c04081b3d9bb810fe6bf825732c9258e94c3db1485377cab6db90255aead3b4e747f9cb9d2db716745
data/.gitignore ADDED
@@ -0,0 +1,44 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /output/
11
+ run-samples
12
+ .DS_Store
13
+
14
+ # Binstubs
15
+ /bin/_guard-core
16
+ /bin/bundler
17
+ /bin/coderay
18
+ /bin/erubis
19
+ /bin/flay
20
+ /bin/flog
21
+ /bin/github-markup
22
+ /bin/guard
23
+ /bin/htmldiff
24
+ /bin/launchy
25
+ /bin/ldiff
26
+ /bin/listen
27
+ /bin/pry
28
+ /bin/rake
29
+ /bin/ramlstyle
30
+ /bin/redcarpet
31
+ /bin/reek
32
+ /bin/rspec
33
+ /bin/rubocop
34
+ /bin/ruby-parse
35
+ /bin/ruby-rewrite
36
+ /bin/ruby_parse
37
+ /bin/ruby_parse_extract_error
38
+ /bin/rubycritic
39
+ /bin/sandi_meter
40
+ /bin/thor
41
+ /bin/unparser
42
+ /bin/yard
43
+ /bin/yardoc
44
+ /bin/yri
data/.rubocop.yml ADDED
@@ -0,0 +1,15 @@
1
+ AllCops:
2
+ Include:
3
+ - '**/Rakefile'
4
+ Exclude:
5
+ - 'bin/*'
6
+
7
+ StringLiterals:
8
+ Enabled: false
9
+ # EnforcedStyle: double_quotes
10
+
11
+ LineLength:
12
+ Max: 120
13
+
14
+ Style/Documentation:
15
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ramlstyle.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,162 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ramlstyle (0.2.3)
5
+ raml_ruby
6
+ redcarpet
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.0.1)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (~> 0.7)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ addressable (2.3.8)
17
+ ast (2.3.0)
18
+ axiom-types (0.1.1)
19
+ descendants_tracker (~> 0.0.4)
20
+ ice_nine (~> 0.11.0)
21
+ thread_safe (~> 0.3, >= 0.3.1)
22
+ codeclimate-engine-rb (0.4.0)
23
+ virtus (~> 1.0)
24
+ coderay (1.1.1)
25
+ coercible (1.0.0)
26
+ descendants_tracker (~> 0.0.1)
27
+ concurrent-ruby (1.0.5)
28
+ descendants_tracker (0.0.4)
29
+ thread_safe (~> 0.3, >= 0.3.1)
30
+ docile (1.1.5)
31
+ equalizer (0.0.11)
32
+ erubis (2.7.0)
33
+ ffi (1.9.17)
34
+ flay (2.8.1)
35
+ erubis (~> 2.7.0)
36
+ path_expander (~> 1.0)
37
+ ruby_parser (~> 3.0)
38
+ sexp_processor (~> 4.0)
39
+ flog (4.6.1)
40
+ path_expander (~> 1.0)
41
+ ruby_parser (~> 3.1, > 3.1.0)
42
+ sexp_processor (~> 4.8)
43
+ formatador (0.2.5)
44
+ guard (2.14.1)
45
+ formatador (>= 0.2.4)
46
+ listen (>= 2.7, < 4.0)
47
+ lumberjack (~> 1.0)
48
+ nenv (~> 0.1)
49
+ notiffany (~> 0.0)
50
+ pry (>= 0.9.12)
51
+ shellany (~> 0.0)
52
+ thor (>= 0.18.1)
53
+ guard-compat (1.2.1)
54
+ guard-minitest (2.4.6)
55
+ guard-compat (~> 1.2)
56
+ minitest (>= 3.0)
57
+ i18n (0.8.1)
58
+ ice_nine (0.11.2)
59
+ json (2.0.3)
60
+ json-schema (2.6.2)
61
+ addressable (~> 2.3.8)
62
+ launchy (2.4.3)
63
+ addressable (~> 2.3)
64
+ listen (3.1.5)
65
+ rb-fsevent (~> 0.9, >= 0.9.4)
66
+ rb-inotify (~> 0.9, >= 0.9.7)
67
+ ruby_dep (~> 1.2)
68
+ lumberjack (1.0.11)
69
+ metaclass (0.0.4)
70
+ method_source (0.8.2)
71
+ minitest (5.10.1)
72
+ mixlib-cli (1.7.0)
73
+ mocha (1.2.1)
74
+ metaclass (~> 0.0.1)
75
+ nenv (0.3.0)
76
+ notiffany (0.1.1)
77
+ nenv (~> 0.1)
78
+ shellany (~> 0.0)
79
+ parser (2.3.3.1)
80
+ ast (~> 2.2)
81
+ path_expander (1.0.1)
82
+ powerpack (0.1.1)
83
+ pry (0.10.4)
84
+ coderay (~> 1.1.0)
85
+ method_source (~> 0.8.1)
86
+ slop (~> 3.4)
87
+ rainbow (2.2.1)
88
+ rake (12.0.0)
89
+ raml_ruby (0.1.2)
90
+ activesupport (>= 4.1)
91
+ json-schema (~> 2.5)
92
+ uri_template (~> 0.7)
93
+ rb-fsevent (0.9.8)
94
+ rb-inotify (0.9.8)
95
+ ffi (>= 0.5.0)
96
+ redcarpet (3.4.0)
97
+ reek (4.5.6)
98
+ codeclimate-engine-rb (~> 0.4.0)
99
+ parser (>= 2.3.1.2, < 2.5)
100
+ rainbow (~> 2.0)
101
+ rubocop (0.47.1)
102
+ parser (>= 2.3.3.1, < 3.0)
103
+ powerpack (~> 0.1)
104
+ rainbow (>= 1.99.1, < 3.0)
105
+ ruby-progressbar (~> 1.7)
106
+ unicode-display_width (~> 1.0, >= 1.0.1)
107
+ ruby-progressbar (1.8.1)
108
+ ruby_dep (1.5.0)
109
+ ruby_parser (3.8.4)
110
+ sexp_processor (~> 4.1)
111
+ rubycritic (3.1.3)
112
+ flay (~> 2.8)
113
+ flog (~> 4.4)
114
+ launchy (= 2.4.3)
115
+ parser (= 2.3.3.1)
116
+ rainbow (~> 2.1)
117
+ reek (~> 4.4)
118
+ ruby_parser (~> 3.8)
119
+ virtus (~> 1.0)
120
+ sandi_meter (1.2.0)
121
+ json
122
+ launchy
123
+ mixlib-cli
124
+ sexp_processor (4.8.0)
125
+ shellany (0.0.1)
126
+ simplecov (0.13.0)
127
+ docile (~> 1.1.0)
128
+ json (>= 1.8, < 3)
129
+ simplecov-html (~> 0.10.0)
130
+ simplecov-html (0.10.0)
131
+ slop (3.6.0)
132
+ thor (0.19.4)
133
+ thread_safe (0.3.6)
134
+ tzinfo (1.2.2)
135
+ thread_safe (~> 0.1)
136
+ unicode-display_width (1.1.3)
137
+ uri_template (0.7.0)
138
+ virtus (1.0.5)
139
+ axiom-types (~> 0.1)
140
+ coercible (~> 1.0)
141
+ descendants_tracker (~> 0.0, >= 0.0.3)
142
+ equalizer (~> 0.0, >= 0.0.9)
143
+
144
+ PLATFORMS
145
+ ruby
146
+
147
+ DEPENDENCIES
148
+ bundler
149
+ guard
150
+ guard-minitest
151
+ minitest
152
+ mocha
153
+ pry
154
+ rake
155
+ ramlstyle!
156
+ rubocop
157
+ rubycritic
158
+ sandi_meter
159
+ simplecov
160
+
161
+ BUNDLED WITH
162
+ 1.14.5
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ guard :minitest do
2
+ watch(%r{^test/(.*)\/?test_(.*)\.rb$})
3
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
4
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
5
+ watch(%r{^templates/(.*)\.erb$}) { 'test' }
6
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2017 Mark Edward Morga
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Ramlstyle
2
+
3
+ Validates the a RAML file, runs lint rules against it, and produces HTML documentation.
4
+
5
+ ## Installation
6
+
7
+ Clone this repository on your machine, install dependencies and install the command.
8
+
9
+ ```sh
10
+ git clone https://github.com/mmorga/ramlstyle.git
11
+ bundle
12
+ sudo bundle exec rake install # if you are using the system Ruby
13
+ bundle exec rake install # if you are using a rbenv, rvm, etc
14
+ ```
15
+
16
+ If you aren't a regular ruby user, you should do this first:
17
+
18
+ ```sh
19
+ sudo gem install bundler
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ Usage: `ramlstyle [options] file1 file2 ...`
25
+
26
+ Option | Description
27
+ -------------------- | -----------
28
+ -v, --verbose | Output more information
29
+ --no-document | Do not produce HTML documentation
30
+ --no-lint | Do not run linter rules
31
+ -o, --output-dir DIR | Write HTML documentation to DIR
32
+ --version | print the version
33
+ -h, --help | Display this screen
34
+
35
+ ## Development
36
+
37
+ 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.
38
+
39
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ramlstyle.
44
+
45
+ ## Credits
46
+
47
+ 1. Templates are derived from templates from [RAML2HTML](https://github.com/kevinrenskers/raml2html)
48
+ 2. RAML is parsed with [raml_ruby](https://github.com/coub/raml_ruby)
49
+
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require "rubocop/rake_task"
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.libs << "lib"
8
+ t.test_files = FileList['test/**/test_*.rb']
9
+ end
10
+
11
+ RuboCop::RakeTask.new do |task|
12
+ task.patterns = ['exe/*', 'lib/**/*.rb', 'test/**/*.rb']
13
+ end
14
+
15
+ desc "Run rubycritic on source and display results"
16
+ task :rubycritic do
17
+ sh "bin/rubycritic;open tmp/rubycritic/overview.html"
18
+ end
19
+
20
+ desc "Run sandi_meter on source and display results"
21
+ task :sandi do
22
+ sh "sandi_meter -o tmp/sandi_meter -g"
23
+ end
24
+
25
+ desc "Run rubocop, rubycritic, and sandi_meter on source and display results"
26
+ task quality: [:rubycritic, :sandi, :rubocop]
27
+
28
+ task default: :test
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'code_climate_reek' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("reek", "code_climate_reek")
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ramlstyle"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
12
+
13
+ # require "irb"
14
+ # IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/ramlstyle ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ramlstyle'
4
+
5
+ Ramlstyle::CLICommand.new.run(ARGV)
@@ -0,0 +1,13 @@
1
+ module Ramlstyle
2
+ class CLICommand
3
+ attr_reader :opts
4
+
5
+ def run(args)
6
+ @opts = Command::Options.new.parse(args)
7
+
8
+ opts.files.each do |raml_file|
9
+ Command::FileCommand.new(opts, raml_file).run
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Ramlstyle
2
+ module Command
3
+ class CommandChain
4
+ def initialize(next_command = EndChain.new)
5
+ @next_command = next_command
6
+ end
7
+
8
+ def run(opts, raml_file, raml)
9
+ @next_command.run(opts, raml_file, raml)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module Ramlstyle
2
+ module Command
3
+ class DocumentCommand < CommandChain
4
+ def run(opts, raml_file, raml)
5
+ Ramlstyle::Document.new(raml)
6
+ .render_to_file(output_file(opts.output_dir, raml_file)) unless opts.no_document
7
+ super(opts, raml_file, raml)
8
+ end
9
+
10
+ private
11
+
12
+ def output_file(output_dir, raml_file)
13
+ File.join(output_dir, "#{File.basename(raml_file, '.raml')}.html")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ module Ramlstyle
2
+ module Command
3
+ class EndChain
4
+ def run(*)
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ module Ramlstyle
2
+ module Command
3
+ class FileCommand
4
+ def initialize(opts, raml_file)
5
+ @opts = opts
6
+ @raml_file = raml_file
7
+ end
8
+
9
+ def run
10
+ puts "\nParsing #{@raml_file}"
11
+
12
+ begin
13
+ ParseCommand.new(ReviewCommand.new(DocumentCommand.new)).run(@opts, @raml_file)
14
+ rescue StandardError => error
15
+ puts error
16
+ print error.backtrace.join("\n") if @opts.trace
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ require "optparse"
2
+
3
+ module Ramlstyle
4
+ module Command
5
+ class Options
6
+ def exit_with_msg(msg)
7
+ puts msg
8
+ exit
9
+ end
10
+
11
+ def parse(arguments)
12
+ settings = Settings.new
13
+ args = arguments.clone # so we don't cause side-effects
14
+ option_parser(settings).parse!(args)
15
+ settings.files = args
16
+ settings.freeze
17
+ end
18
+
19
+ def option_parser(settings)
20
+ OptionParser.new do |opts|
21
+ opts.banner = "Usage: rubystyle [options] file1 file2 ..."
22
+ opts.on('-v', '--verbose', 'Output more information') { settings.verbose = true }
23
+ opts.on('-t', '--trace', 'Output stack trace on error') { settings.trace = true }
24
+ opts.on('--no-document', 'Do not produce HTML documentation') { settings.no_document = true }
25
+ opts.on('--no-lint', 'Do not run linter rules') { settings.no_lint = true }
26
+ opts.on('-o', '--output-dir DIR', 'Write HTML documentation to DIR') { |dir| settings.output_dir = dir }
27
+ opts.on('--version', 'print the version') { exit_with_msg(Ramlstyle::VERSION) }
28
+ opts.on('-h', '--help', 'Display this screen') { exit_with_msg(opts) }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ module Ramlstyle
2
+ module Command
3
+ class ParseCommand < CommandChain
4
+ def run(opts, raml_file)
5
+ super(opts, raml_file, Ramlstyle::RamlParser.new(raml_file).parse)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Ramlstyle
2
+ module Command
3
+ class ReviewCommand < CommandChain
4
+ def run(opts, raml_file, raml)
5
+ Ramlstyle::Review.new(raml).review unless opts.no_lint
6
+ super(opts, raml_file, raml)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ module Ramlstyle
2
+ module Command
3
+ class Settings
4
+ attr_accessor :verbose, :no_document, :no_lint, :output_dir, :files, :trace
5
+
6
+ def initialize
7
+ @verbose = false
8
+ @trace = false
9
+ @no_document = false
10
+ @no_lint = false
11
+ @output_dir = Dir.getwd
12
+ @files = []
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module Ramlstyle
2
+ class Document
3
+ def initialize(obj)
4
+ @obj = obj
5
+ end
6
+
7
+ def render
8
+ Documentation::RendererFactory.new.renderer_for_root(@obj).render
9
+ end
10
+
11
+ def render_to_file(file_name)
12
+ IO.write(file_name, render)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,52 @@
1
+ module Ramlstyle
2
+ module Documentation
3
+ class ERBContext
4
+ include ERB::Util
5
+
6
+ def initialize(hash)
7
+ @options = {}
8
+ @markdown = Redcarpet::Markdown.new(
9
+ Redcarpet::Render::SmartyHTML,
10
+ no_intra_emphasis: true,
11
+ tables: true,
12
+ fenced_code_blocks: true,
13
+ autolink: true,
14
+ strikethrough: true,
15
+ underline: true,
16
+ quote: true,
17
+ footnotes: true
18
+ )
19
+ hash.each_pair do |key, value|
20
+ instance_variable_set('@' + key.to_s, value)
21
+ end
22
+ end
23
+
24
+ def markdown(str)
25
+ @markdown.render(str || "")
26
+ end
27
+
28
+ def render_resource(res)
29
+ RendererFactory.new.renderer_for_resource(res).render
30
+ end
31
+
32
+ def render_parameter(param)
33
+ RendererFactory.new.renderer_for_parameter(param).render
34
+ end
35
+
36
+ def secured?(obj)
37
+ return true if obj.secured_by.count { |s| s.name == "null" } > 0
38
+ return true if obj.security_scheme_declarations.count { |s| s.name == "null" } > 0
39
+ false
40
+ end
41
+
42
+ def security_scheme_names(obj)
43
+ return obj.secured_by.map(&:name) if obj.secured_by.length > 0
44
+ obj.security_scheme_declarations.map(&:name)
45
+ end
46
+
47
+ def context_binding
48
+ binding
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,14 @@
1
+ module Ramlstyle
2
+ module Documentation
3
+ class Renderer
4
+ def initialize(template, template_var_hash)
5
+ @template = ERB.new(File.read(template))
6
+ @context = ERBContext.new(template_var_hash)
7
+ end
8
+
9
+ def render
10
+ @template.result(@context.context_binding)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ module Ramlstyle
2
+ module Documentation
3
+ class RendererFactory
4
+ def renderer_for_parameter(param)
5
+ Renderer.new(File.join(Ramlstyle::TEMPLATES_PATH, 'item.html.erb'), item: param, key: param.name)
6
+ end
7
+
8
+ def renderer_for_resource(res)
9
+ Renderer.new(File.join(Ramlstyle::TEMPLATES_PATH, 'resource.html.erb'), resource: res)
10
+ end
11
+
12
+ def renderer_for_root(root)
13
+ Renderer.new(File.join(Ramlstyle::TEMPLATES_PATH, 'template.html.erb'), raml: root)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ module Raml
2
+ class Node
3
+ # A method that gives you the full path of the node to make it easier to find the error.
4
+ def path_name
5
+ File.join(parent.path_name, name.to_s)
6
+ end
7
+
8
+ def parent_url
9
+ parent.path_name
10
+ end
11
+
12
+ def unique_id
13
+ path_name.gsub(%r([\/\{\}]), "_")
14
+ end
15
+
16
+ def all_uri_parameters
17
+ children.select { |child| child.is_a? Raml::Parameter::UriParameter }
18
+ end
19
+
20
+ def query_parameters
21
+ children.select { |child| child.is_a? Raml::Parameter::QueryParameter }
22
+ end
23
+
24
+ def form_parameters
25
+ children.select { |child| child.is_a? Raml::Parameter::FormParameter }
26
+ end
27
+ end
28
+ end