flagdoc 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 66bb3e6afa2f66c4744131898a5a8177c5cfde51b0223077766253ae8860ac86
4
+ data.tar.gz: 7d3a4864e0ded1194139fcc00d8e6b7a96cfc3628a8595b0447a926974a47dba
5
+ SHA512:
6
+ metadata.gz: 8ae77886b49cb1841e5939ac979f51f32542cc7cdc228ba1789f5662174e037fc4e35706615985263bd3743fdccb6107c661b9d8619b5f081b0d510afc75ebde
7
+ data.tar.gz: 31ce8298222284510cdbfaa504efe0bbc0622e9d27e81d1b87a635eec14d004aea0c3b8981517c45a156bdb6ef58c87bb670b5fc148a0d44fac3e780c3b34166
@@ -0,0 +1,49 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.5.0-node-browsers
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/postgres:9.4
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+
22
+ # Download and cache dependencies
23
+ - restore_cache:
24
+ keys:
25
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
26
+ # fallback to using the latest cache if no exact match is found
27
+ - v1-dependencies-
28
+
29
+ - run:
30
+ name: install dependencies
31
+ command: |
32
+ gem install bundler
33
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
34
+ - save_cache:
35
+ paths:
36
+ - ./vendor/bundle
37
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
38
+
39
+ # run tests!
40
+ - run:
41
+ name: run tests
42
+ command: |
43
+ bundle exec rspec
44
+ # collect reports
45
+ - store_test_results:
46
+ path: /tmp/test-results
47
+ - store_artifacts:
48
+ path: /tmp/test-results
49
+ destination: test-results
data/.codeclimate.yml ADDED
@@ -0,0 +1,9 @@
1
+ plugins:
2
+ reek:
3
+ enabled: true
4
+ rubocop:
5
+ enabled: true
6
+ flog:
7
+ enabled: true
8
+ config:
9
+ score_threshold: 20.0
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.1.1] - 2018-09-11
8
+ ### Fixed
9
+ - Rubygem same version error
10
+
11
+ ## [0.1.0] - 2018-09-11
12
+ ### Added
13
+ - Codeclimate to have automated code review
14
+ - InchCi to display documentation badge
15
+ - CircleCi for Continuous Integration
16
+ - Simplecov for test coverage
17
+ - RSpec for tests
18
+ - Ruby version 2.5.1
19
+ - Initialize project with the search for flags, a priority manager, and a beautiful STDOUT :)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flagdoc.gemspec
4
+ gemspec
5
+ # Behaviour Driven Development for Ruby
6
+ gem 'rspec'
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ flagdoc (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ diff-lcs (1.3)
11
+ docile (1.3.1)
12
+ json (2.1.0)
13
+ method_source (0.9.0)
14
+ pry (0.11.3)
15
+ coderay (~> 1.1.0)
16
+ method_source (~> 0.9.0)
17
+ rake (10.5.0)
18
+ rspec (3.8.0)
19
+ rspec-core (~> 3.8.0)
20
+ rspec-expectations (~> 3.8.0)
21
+ rspec-mocks (~> 3.8.0)
22
+ rspec-core (3.8.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-expectations (3.8.1)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-mocks (3.8.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-support (3.8.0)
31
+ simplecov (0.16.1)
32
+ docile (~> 1.1)
33
+ json (>= 1.8, < 3)
34
+ simplecov-html (~> 0.10.0)
35
+ simplecov-html (0.10.2)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ bundler (~> 1.16)
42
+ flagdoc!
43
+ pry (~> 0.11)
44
+ rake (~> 10.0)
45
+ rspec
46
+ simplecov (~> 0.16)
47
+
48
+ BUNDLED WITH
49
+ 1.16.2
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ <h1 align="center">Flagdoc</h1>
2
+
3
+ <br/>
4
+
5
+ <div align="center">
6
+ <a href='https://semaphoreci.com/nicolaslechenic/flagdoc'>
7
+ <img src='https://circleci.com/gh/nicolaslechenic/flagdoc/tree/master.svg?style=svg' alt='Build Status'>
8
+ </a>
9
+
10
+ <a href="https://codeclimate.com/github/nicolaslechenic/flagdoc/maintainability">
11
+ <img src="https://api.codeclimate.com/v1/badges/f7ce259947e2019f1e9f/maintainability" />
12
+ </a>
13
+
14
+ <a href="http://inch-ci.org/github/nicolaslechenic/flagdoc">
15
+ <img src="http://inch-ci.org/github/nicolaslechenic/flagdoc.svg?branch=master" />
16
+ </a>
17
+ </div>
18
+
19
+ ---
20
+
21
+ Flagdoc is an alternative to the rails notes inspired by the Yardoc syntax. Now, you can add customs flags with priority level
22
+
23
+ **./example/file.rb**
24
+
25
+ ```ruby
26
+ # @flag [OLD, HIGH] being removed, prefere bar method
27
+ def foo
28
+ # Do something...
29
+ end
30
+
31
+ # @flag [NEW] replacing foo method
32
+ def bar
33
+ # Do something...
34
+ end
35
+
36
+ # @flag [TODO, LOW] must be renamed to baz
37
+ def bazz
38
+ # Do something...
39
+ end
40
+ ```
41
+
42
+ Will return something like that:
43
+
44
+ ![Terminal STDOUT](/files/example.png)
45
+
46
+ ## Levels:
47
+
48
+ - LOW
49
+ - NORMAL
50
+ - HIGH
51
+
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/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'flagdoc'
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(__FILE__)
data/bin/flagdoc ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require_relative '../lib/flagdoc'
5
+ require 'pry'
6
+
7
+ store = Flagdoc::Store.new
8
+
9
+ Dir['./**/*.rb'].each do |file|
10
+ strings = `grep -rn '# @flag' #{file}`
11
+
12
+ next if strings.empty?
13
+ strings.split("\n").each do |string|
14
+ parse = Flagdoc::Parser.new(string: string)
15
+
16
+ store.add(
17
+ path: parse.path,
18
+ line: parse.line,
19
+ type: parse.type,
20
+ priority: parse.priority,
21
+ description: parse.description
22
+ )
23
+ end
24
+ end
25
+
26
+ Flagdoc::Stream.new(store: store).()
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
data/files/example.png ADDED
Binary file
data/flagdoc.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'flagdoc/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'flagdoc'
7
+ spec.version = Flagdoc::VERSION
8
+ spec.authors = ['Nicolas LE CHENIC']
9
+ spec.email = ['pro.nicolaslechenic@gmail.com']
10
+
11
+ spec.summary = 'Displays the flags written in your ruby ​​code'
12
+ spec.homepage = 'https://github.com/nicolaslechenic/flagdoc'
13
+ spec.files =
14
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
15
+
16
+ spec.license = 'MIT'
17
+ spec.executables = ['flagdoc']
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.16'
21
+ spec.add_development_dependency 'pry', '~> 0.11'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+ spec.add_development_dependency 'simplecov', '~> 0.16'
25
+ end
@@ -0,0 +1,55 @@
1
+ module Flagdoc
2
+ # @since 0.1.0
3
+ class Parser
4
+ SPLIT_ORDER =
5
+ {
6
+ 'path' => 0,
7
+ 'line' => 1
8
+ }.freeze
9
+
10
+ def initialize(string:)
11
+ @string = string
12
+ end
13
+
14
+ # Generate methods:
15
+ # - path
16
+ # - line
17
+ #
18
+ # @since 0.1.0
19
+ #
20
+ # @return [String] with the information that depends
21
+ # on the name of the method
22
+ SPLIT_ORDER.each do |type, order|
23
+ define_method(type.to_s) { splitted[order] }
24
+ end
25
+
26
+ # @since 0.1.0
27
+ def type
28
+ type_and_priority.first.strip
29
+ end
30
+
31
+ # @since 0.1.0
32
+ def priority
33
+ return 'NORMAL' unless type_and_priority.count > 1
34
+ priority = type_and_priority.last.strip
35
+
36
+ Priority.available?(priority) ? priority : 'NORMAL'
37
+ end
38
+
39
+ # @since 0.1.0
40
+ def description
41
+ splitted[2].split(']').last.strip
42
+ end
43
+
44
+ private
45
+
46
+ def splitted
47
+ @splitted ||= @string.split(':')
48
+ end
49
+
50
+ def type_and_priority
51
+ @type_and_priority ||=
52
+ splitted[2][/\[(.*)\]/m, 1].strip.split(',')
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,39 @@
1
+ # Flagdoc is used to display custom flags with
2
+ # priority manager in your terminal
3
+ #
4
+ # After installation you just need to enter flagdoc in
5
+ # your terminal to display the available flags into the
6
+ # current folder
7
+ #
8
+ # The syntax used is inspired by yardoc:
9
+ #
10
+ # @flag [MESSAGE, LOW] Hello world !
11
+ module Flagdoc
12
+ # Define priorities levels
13
+ #
14
+ # @since 0.1.0
15
+ class Priority
16
+ LEVELS =
17
+ {
18
+ 'LOW' => '29',
19
+ 'NORMAL' => '166',
20
+ 'HIGH' => '196'
21
+ }.freeze
22
+
23
+ class << self
24
+ # @since 0.1.0
25
+ #
26
+ # @return [Boolean] true if the priority is available
27
+ def available?(priority)
28
+ LEVELS.key?(priority)
29
+ end
30
+
31
+ # @since 0.1.0
32
+ #
33
+ # @return [String] with bash color code
34
+ def color_code(priority)
35
+ '48;5;' + LEVELS[priority]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,55 @@
1
+ module Flagdoc
2
+ # Store parsed flags informations
3
+ #
4
+ # @since 0.1.0
5
+ class Store
6
+ attr_reader :files
7
+
8
+ # Store files data with flags infos
9
+ def initialize
10
+ @files = []
11
+ end
12
+
13
+ # Add flag to file path if already exist
14
+ # then add file path and flag to @files
15
+ #
16
+ # @since 0.1.0
17
+ def add(args)
18
+ return unless valid?(args)
19
+
20
+ flag = serialize_flag(args)
21
+ file = find_by_path(args[:path])
22
+
23
+ if file
24
+ file[:flags] << flag
25
+ else
26
+ add_file(args, flag)
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ # @return [Boolean] true if all args are ok
33
+ def valid?(args)
34
+ Priority.available?(args[:priority])
35
+ end
36
+
37
+ # @return [Hash] file with path
38
+ def find_by_path(path)
39
+ @files.find { |file| file[:path] == path }
40
+ end
41
+
42
+ def add_file(args, flag)
43
+ @files << { path: args[:path], flags: [flag] }
44
+ end
45
+
46
+ def serialize_flag(args)
47
+ {
48
+ type: args[:type],
49
+ priority: args[:priority],
50
+ line: args[:line],
51
+ description: args[:description]
52
+ }
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,111 @@
1
+ module Flagdoc
2
+ # Display parsed flags informations
3
+ #
4
+ # @since 0.1.0
5
+ class Stream
6
+ BOX_SIZE = 54
7
+ LINE_SIZE = 12
8
+ TAB_SIZE = 2
9
+ COLORS =
10
+ {
11
+ 'line' => '90;48;5;192',
12
+ 'description' => '90;48;5;194',
13
+ 'file' => '33;1'
14
+ }.freeze
15
+
16
+ # @since 1.0.1
17
+ def initialize(store:)
18
+ @store = store
19
+ end
20
+
21
+ # Launch the stream of stored informations
22
+ #
23
+ # @since 1.0.1
24
+ #
25
+ # @return [STDOUT] with formatted informations
26
+ def call
27
+ @store.files.each do |file|
28
+ file_path(file[:path])
29
+ flags(file[:flags])
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ # Generate methods:
36
+ # - file_color
37
+ # - line_color
38
+ # - description_color
39
+ #
40
+ # @return [String] with bash color code
41
+ COLORS.each do |type, code|
42
+ define_method("#{type}_color") { code }
43
+ end
44
+
45
+ def type_color(priority)
46
+ "1;97;#{Priority.color_code(priority)}"
47
+ end
48
+
49
+ # @return [STDOUT] colored file path
50
+ def file_path(path)
51
+ puts
52
+ puts "\e[#{file_color}m#{path}\e[0m"
53
+ puts
54
+ end
55
+
56
+ # @return [STDOUT] colored flags
57
+ def flags(flags)
58
+ flags.each do |flag|
59
+ head(flag[:type], "line #{flag[:line]}", flag[:priority])
60
+ blank
61
+ content(flag[:description])
62
+ blank
63
+ puts
64
+ end
65
+ end
66
+
67
+ def head(type, line, priority)
68
+ space_line = space_line(LINE_SIZE - line.length)
69
+ space_type = space_line((BOX_SIZE - LINE_SIZE - 2) - type.length)
70
+ line_content = colorize(line_color, space_line + line)
71
+ type_content = colorize(type_color(priority), type + space_type)
72
+
73
+ puts "#{tab}#{type_content}#{line_content}"
74
+ end
75
+
76
+ def blank
77
+ blank =
78
+ colorize(description_color, space_line(BOX_SIZE))
79
+
80
+ puts "#{tab}#{blank}"
81
+ end
82
+
83
+ def content(description)
84
+ space_description = space_line(BOX_SIZE - description.length)
85
+
86
+ description_content =
87
+ colorize(
88
+ description_color,
89
+ description.capitalize + space_description
90
+ )
91
+
92
+ puts "#{tab}#{description_content}"
93
+ end
94
+
95
+ def space_line(number)
96
+ ' ' * number
97
+ end
98
+
99
+ def tab(number = 1)
100
+ space_line(TAB_SIZE * number)
101
+ end
102
+
103
+ def colorize(color, content)
104
+ format(
105
+ "\e[%<color>sm %<content>s \e[0m",
106
+ color: color,
107
+ content: content
108
+ )
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,6 @@
1
+ module Flagdoc
2
+ # Flagdoc version
3
+ #
4
+ # @since 0.1.0
5
+ VERSION = '0.1.1'.freeze
6
+ end
data/lib/flagdoc.rb ADDED
@@ -0,0 +1,3 @@
1
+ %w[parser priority store stream version].each do |file|
2
+ require_relative "flagdoc/#{file}"
3
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flagdoc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas LE CHENIC
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-11 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: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.11'
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.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.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: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.16'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.16'
83
+ description:
84
+ email:
85
+ - pro.nicolaslechenic@gmail.com
86
+ executables:
87
+ - flagdoc
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".circleci/config.yml"
92
+ - ".codeclimate.yml"
93
+ - ".gitignore"
94
+ - ".rspec"
95
+ - ".ruby-version"
96
+ - CHANGELOG.md
97
+ - Gemfile
98
+ - Gemfile.lock
99
+ - README.md
100
+ - Rakefile
101
+ - bin/console
102
+ - bin/flagdoc
103
+ - bin/setup
104
+ - files/example.png
105
+ - flagdoc.gemspec
106
+ - lib/flagdoc.rb
107
+ - lib/flagdoc/parser.rb
108
+ - lib/flagdoc/priority.rb
109
+ - lib/flagdoc/store.rb
110
+ - lib/flagdoc/stream.rb
111
+ - lib/flagdoc/version.rb
112
+ homepage: https://github.com/nicolaslechenic/flagdoc
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.7.6
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Displays the flags written in your ruby ​​code
136
+ test_files: []