bundle_outdated_formatter 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b3dde0537afc9e0b41231b98bffc5a06c999606
4
- data.tar.gz: a09cc4304d66a60814b7d4a5207a6c413656cabc
3
+ metadata.gz: 46d8e274c48811f1a392cf4c0535b82d2aca4df7
4
+ data.tar.gz: a64b6f0deea5b0af8bf91060aa8a87ebf1a713e9
5
5
  SHA512:
6
- metadata.gz: aff545d992a1538144e298782be897a0aace41f06b215816649478cf6ec15a0a3d5c9e2920ea1008ac34ce8b1a9e978dee293f202e76e9f3660f925b699d87b2
7
- data.tar.gz: 25f5195074d504e5a9e5e5433eb98ec9464bfe3806281df5438ab110103ff9055d68d8be96fe28e1cebf696c9e6c66c07c702dfc3cbd9df07067a50b984642db
6
+ metadata.gz: 2834c969fe8cab275e2909b75fc5394fb835b39e331c0f6e0796fa47351aedee8ae968cf0923c200f532291312e79ad85ce1f9f8e231debe175b64509ac3ab1a
7
+ data.tar.gz: afb16f7d8bfe1f683bbf718d368b269997a95f7389de780024b73b4e1c7c2a1ea5b94eb5e0dd17d169eca4bf1ba3c0852f435ec805eadc9a1438dd91bc4f6338
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2017-06-10 17:56:18 +0900 using RuboCop version 0.49.1.
3
+ # on 2017-06-19 20:57:55 +0900 using RuboCop version 0.49.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -12,41 +12,37 @@ Layout/EmptyLineAfterMagicComment:
12
12
  Exclude:
13
13
  - 'bundle_outdated_formatter.gemspec'
14
14
 
15
- # Offense count: 1
16
- # Cop supports --auto-correct.
17
- # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
18
- Layout/ExtraSpacing:
19
- Exclude:
20
- - 'bundle_outdated_formatter.gemspec'
15
+ # Offense count: 2
16
+ Metrics/AbcSize:
17
+ Max: 23
21
18
 
22
19
  # Offense count: 1
23
- # Cop supports --auto-correct.
24
- # Configuration parameters: AllowForAlignment.
25
- Layout/SpaceAroundOperators:
26
- Exclude:
27
- - 'bundle_outdated_formatter.gemspec'
20
+ # Configuration parameters: CountComments.
21
+ Metrics/ClassLength:
22
+ Max: 102
28
23
 
29
24
  # Offense count: 1
30
- Metrics/AbcSize:
31
- Max: 23
25
+ Metrics/CyclomaticComplexity:
26
+ Max: 7
32
27
 
33
- # Offense count: 5
28
+ # Offense count: 8
34
29
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
35
30
  # URISchemes: http, https
36
31
  Metrics/LineLength:
37
32
  Max: 126
38
33
 
39
- # Offense count: 1
34
+ # Offense count: 4
40
35
  # Configuration parameters: CountComments.
41
36
  Metrics/MethodLength:
42
37
  Max: 20
43
38
 
44
- # Offense count: 1
39
+ # Offense count: 2
45
40
  Style/Documentation:
46
41
  Exclude:
47
42
  - 'spec/**/*'
48
43
  - 'test/**/*'
49
44
  - 'lib/bundle_outdated_formatter/cli.rb'
45
+ - 'lib/bundle_outdated_formatter/formatter.rb'
50
46
 
51
47
  # Offense count: 1
52
48
  # Cop supports --auto-correct.
@@ -56,12 +52,6 @@ Style/HashSyntax:
56
52
  Exclude:
57
53
  - 'Rakefile'
58
54
 
59
- # Offense count: 1
60
- # Cop supports --auto-correct.
61
- Style/MutableConstant:
62
- Exclude:
63
- - 'lib/bundle_outdated_formatter/version.rb'
64
-
65
55
  # Offense count: 2
66
56
  # Cop supports --auto-correct.
67
57
  # Configuration parameters: PreferredDelimiters.
@@ -69,12 +59,6 @@ Style/PercentLiteralDelimiters:
69
59
  Exclude:
70
60
  - 'bundle_outdated_formatter.gemspec'
71
61
 
72
- # Offense count: 5
73
- # Cop supports --auto-correct.
74
- Style/RedundantFreeze:
75
- Exclude:
76
- - 'lib/bundle_outdated_formatter/cli.rb'
77
-
78
62
  # Offense count: 2
79
63
  # Cop supports --auto-correct.
80
64
  Style/UnneededPercentQ:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.0 (2017-06-19)
4
+
5
+ ### Features
6
+
7
+ * Support JSON format
8
+ * Support YAML format
9
+ * Support CSV format
10
+ * Support XML format
11
+ * Support HTML format
12
+
3
13
  ## 0.1.0 (2017-06-15)
4
14
 
5
15
  ### Features
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # BundleOutdatedFormatter
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/bundle_outdated_formatter.svg)](https://badge.fury.io/rb/bundle_outdated_formatter)
3
4
  [![Build Status](https://travis-ci.org/emsk/bundle_outdated_formatter.svg?branch=master)](https://travis-ci.org/emsk/bundle_outdated_formatter)
4
5
  [![Coverage Status](https://coveralls.io/repos/github/emsk/bundle_outdated_formatter/badge.svg?branch=master)](https://coveralls.io/github/emsk/bundle_outdated_formatter)
5
6
  [![Code Climate](https://codeclimate.com/github/emsk/bundle_outdated_formatter/badges/gpa.svg)](https://codeclimate.com/github/emsk/bundle_outdated_formatter)
@@ -31,12 +32,16 @@ $ gem install bundle_outdated_formatter
31
32
 
32
33
  ## Usage
33
34
 
34
- ### Convert to Markdown
35
-
36
35
  ```sh
37
36
  $ bundle outdated | bof
38
37
  ```
39
38
 
39
+ ## Command Options
40
+
41
+ | Option | Alias | Description | Default |
42
+ | :----- | :---- | :---------- | :------ |
43
+ | `--format` | `-f` | Format. `markdown`, `json`, `yaml`, `csv`, `xml`, or `html`. | `markdown` |
44
+
40
45
  ## Examples
41
46
 
42
47
  Output of `bundle outdated`:
@@ -63,6 +68,54 @@ Outdated gems included in the bundle:
63
68
  | headless | 2.3.1 | 2.2.3 | | |
64
69
  ```
65
70
 
71
+ ### Convert to JSON
72
+
73
+ ```
74
+ [{"gem":"faker","newest":"1.6.6","installed":"1.6.5","requested":"~> 1.4","groups":"development, test"},{"gem":"hashie","newest":"3.4.6","installed":"1.2.0","requested":"= 1.2.0","groups":"default"},{"gem":"headless","newest":"2.3.1","installed":"2.2.3","requested":"","groups":""}]
75
+ ```
76
+
77
+ ### Convert to YAML
78
+
79
+ ```
80
+ ---
81
+ - gem: faker
82
+ newest: 1.6.6
83
+ installed: 1.6.5
84
+ requested: "~> 1.4"
85
+ groups: development, test
86
+ - gem: hashie
87
+ newest: 3.4.6
88
+ installed: 1.2.0
89
+ requested: "= 1.2.0"
90
+ groups: default
91
+ - gem: headless
92
+ newest: 2.3.1
93
+ installed: 2.2.3
94
+ requested: ''
95
+ groups: ''
96
+ ```
97
+
98
+ ### Convert to CSV
99
+
100
+ ```
101
+ "gem","newest","installed","requested","groups"
102
+ "faker","1.6.6","1.6.5","~> 1.4","development, test"
103
+ "hashie","3.4.6","1.2.0","= 1.2.0","default"
104
+ "headless","2.3.1","2.2.3","",""
105
+ ```
106
+
107
+ ### Convert to XML
108
+
109
+ ```
110
+ <?xml version='1.0' encoding='UTF-8'?><gems><outdated><gem>faker</gem><newest>1.6.6</newest><installed>1.6.5</installed><requested>~> 1.4</requested><groups>development, test</groups></outdated><outdated><gem>hashie</gem><newest>3.4.6</newest><installed>1.2.0</installed><requested>= 1.2.0</requested><groups>default</groups></outdated><outdated><gem>headless</gem><newest>2.3.1</newest><installed>2.2.3</installed><requested></requested><groups></groups></outdated></gems>
111
+ ```
112
+
113
+ ### Convert to HTML
114
+
115
+ ```
116
+ <table><tr><th>gem</th><th>newest</th><th>installed</th><th>requested</th><th>groups</th></tr><tr><td>faker</td><td>1.6.6</td><td>1.6.5</td><td>~> 1.4</td><td>development, test</td></tr><tr><td>hashie</td><td>3.4.6</td><td>1.2.0</td><td>= 1.2.0</td><td>default</td></tr><tr><td>headless</td><td>2.3.1</td><td>2.2.3</td><td></td><td></td></tr></table>
117
+ ```
118
+
66
119
  ## Supported Ruby Versions
67
120
 
68
121
  * Ruby 2.0.0
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ['lib']
23
23
 
24
+ spec.add_runtime_dependency 'psych', '~> 2.2'
24
25
  spec.add_runtime_dependency 'thor', '~> 0.19'
25
26
  spec.add_development_dependency 'bundler', '~> 1.15'
26
27
  spec.add_development_dependency 'coveralls', '~> 0.8'
@@ -1,27 +1,22 @@
1
1
  require 'thor'
2
+ require 'bundle_outdated_formatter/formatter'
2
3
 
3
4
  module BundleOutdatedFormatter
4
5
  class CLI < Thor
5
- NAME_REGEXP = /\A(\* )*(?<name>.+) \(/.freeze
6
- NEWEST_REGEXP = /newest (?<newest>[\d\.]+)/.freeze
7
- INSTALLED_REGEXP = /installed (?<installed>[\d\.]+)/.freeze
8
- REQUESTED_REGEXP = /requested (?<requested>.+)\)/.freeze
9
- GROUPS_REGEXP = /in groups "(?<groups>.+)"/.freeze
10
-
11
- MARKDOWN_HEADER = <<-EOS.freeze
12
- | gem | newest | installed | requested | groups |
13
- | --- | --- | --- | --- | --- |
14
- EOS
6
+ ALLOW_FORMAT = %w[markdown json yaml csv xml html].freeze
15
7
 
16
8
  default_command :output
17
9
 
18
10
  desc 'output', 'Format output of `bundle outdated`'
19
- option :format, type: :string, aliases: '-f', default: 'markdown'
11
+ option :format, type: :string, aliases: '-f', default: 'markdown', desc: 'Format. (markdown, json, yaml, csv, xml, html)'
20
12
 
21
13
  def output
22
14
  return if STDIN.tty?
15
+ return unless allow_format?
23
16
 
24
- puts format_markdown(outdated_gems_in_stdin) if options[:format] == 'markdown'
17
+ formatter = Formatter.new(options[:format])
18
+ formatter.read_stdin
19
+ puts formatter.convert
25
20
  end
26
21
 
27
22
  desc 'version, -v, --version', 'Print the version'
@@ -33,42 +28,8 @@ module BundleOutdatedFormatter
33
28
 
34
29
  private
35
30
 
36
- def outdated_gems_in_stdin
37
- outdated_gems = STDIN.each.to_a.map(&:strip).reject(&:empty?)
38
-
39
- outdated_gems.map! do |line|
40
- matched_name = NAME_REGEXP.match(line)
41
- matched_newest = NEWEST_REGEXP.match(line)
42
- matched_installed = INSTALLED_REGEXP.match(line)
43
- matched_requested = REQUESTED_REGEXP.match(line)
44
- matched_groups = GROUPS_REGEXP.match(line)
45
-
46
- if matched_name.nil? && matched_newest.nil? && matched_installed.nil? && matched_requested.nil? && matched_groups.nil?
47
- nil
48
- else
49
- {
50
- name: gem_text(matched_name, :name),
51
- newest: gem_text(matched_newest, :newest),
52
- installed: gem_text(matched_installed, :installed),
53
- requested: gem_text(matched_requested, :requested),
54
- groups: gem_text(matched_groups, :groups)
55
- }
56
- end
57
- end
58
-
59
- outdated_gems.compact
60
- end
61
-
62
- def gem_text(text, name)
63
- text ? text[name] : ''
64
- end
65
-
66
- def format_markdown(outdated_gems)
67
- outdated_gems.map! do |gem|
68
- "| #{[gem[:name], gem[:newest], gem[:installed], gem[:requested], gem[:groups]].join(' | ')} |".gsub(/ /, ' ')
69
- end
70
-
71
- MARKDOWN_HEADER + outdated_gems.join("\n")
31
+ def allow_format?
32
+ ALLOW_FORMAT.include?(options[:format])
72
33
  end
73
34
  end
74
35
  end
@@ -0,0 +1,136 @@
1
+ require 'json'
2
+ require 'psych'
3
+ require 'csv'
4
+ require 'rexml/document'
5
+
6
+ module BundleOutdatedFormatter
7
+ class Formatter
8
+ NAME_REGEXP = /\A(\* )*(?<name>.+) \(/
9
+ NEWEST_REGEXP = /newest (?<newest>[\d\.]+)/
10
+ INSTALLED_REGEXP = /installed (?<installed>[\d\.]+)/
11
+ REQUESTED_REGEXP = /requested (?<requested>.+)\)/
12
+ GROUPS_REGEXP = /in groups "(?<groups>.+)"/
13
+
14
+ MARKDOWN_HEADER = <<-EOS.freeze
15
+ | gem | newest | installed | requested | groups |
16
+ | --- | --- | --- | --- | --- |
17
+ EOS
18
+ COLUMNS = %w[gem newest installed requested groups].freeze
19
+
20
+ def initialize(format)
21
+ @format = format
22
+ @outdated_gems = []
23
+ end
24
+
25
+ def read_stdin
26
+ @outdated_gems = STDIN.each.to_a.map(&:strip).reject(&:empty?)
27
+
28
+ @outdated_gems.map! do |line|
29
+ matched_name = NAME_REGEXP.match(line)
30
+ matched_newest = NEWEST_REGEXP.match(line)
31
+ matched_installed = INSTALLED_REGEXP.match(line)
32
+ matched_requested = REQUESTED_REGEXP.match(line)
33
+ matched_groups = GROUPS_REGEXP.match(line)
34
+
35
+ if matched_name.nil? && matched_newest.nil? && matched_installed.nil? && matched_requested.nil? && matched_groups.nil?
36
+ nil
37
+ else
38
+ {
39
+ 'gem' => gem_text(matched_name, :name),
40
+ 'newest' => gem_text(matched_newest, :newest),
41
+ 'installed' => gem_text(matched_installed, :installed),
42
+ 'requested' => gem_text(matched_requested, :requested),
43
+ 'groups' => gem_text(matched_groups, :groups)
44
+ }
45
+ end
46
+ end
47
+
48
+ @outdated_gems.compact!
49
+ end
50
+
51
+ def convert
52
+ text =
53
+ case @format
54
+ when 'markdown' then format_markdown
55
+ when 'json' then format_json
56
+ when 'yaml' then format_yaml
57
+ when 'csv' then format_csv
58
+ when 'xml' then format_xml
59
+ when 'html' then format_html
60
+ else ''
61
+ end
62
+ text.chomp
63
+ end
64
+
65
+ private
66
+
67
+ def format_markdown
68
+ @outdated_gems.map! do |gem|
69
+ "| #{gem.values.join(' | ')} |".gsub(/ /, ' ')
70
+ end
71
+
72
+ MARKDOWN_HEADER + @outdated_gems.join("\n")
73
+ end
74
+
75
+ def format_json
76
+ @outdated_gems.to_json
77
+ end
78
+
79
+ def format_yaml
80
+ @outdated_gems.to_yaml
81
+ end
82
+
83
+ def format_csv
84
+ CSV.generate(force_quotes: true) do |csv|
85
+ csv << COLUMNS
86
+ @outdated_gems.each do |gem|
87
+ csv << gem.values
88
+ end
89
+ end
90
+ end
91
+
92
+ def format_xml
93
+ xml = REXML::Document.new(nil, raw: :all)
94
+ xml << REXML::XMLDecl.new('1.0', 'UTF-8')
95
+
96
+ root = REXML::Element.new('gems')
97
+ xml.add_element(root)
98
+
99
+ @outdated_gems.each do |gem|
100
+ elements = root.add_element(REXML::Element.new('outdated'))
101
+
102
+ COLUMNS.each do |column|
103
+ elements.add_element(column).add_text(gem[column])
104
+ end
105
+ end
106
+
107
+ xml.to_s
108
+ end
109
+
110
+ def format_html
111
+ html = REXML::Document.new(nil, raw: :all)
112
+
113
+ root = REXML::Element.new('table')
114
+ html.add_element(root)
115
+
116
+ elements = root.add_element(REXML::Element.new('tr'))
117
+ COLUMNS.each do |column|
118
+ elements.add_element('th').add_text(column)
119
+ end
120
+
121
+ @outdated_gems.each do |gem|
122
+ elements = root.add_element(REXML::Element.new('tr'))
123
+
124
+ COLUMNS.each do |column|
125
+ elements.add_element('td').add_text(gem[column])
126
+ end
127
+ end
128
+
129
+ html.to_s
130
+ end
131
+
132
+ def gem_text(text, name)
133
+ text ? text[name] : ''
134
+ end
135
+ end
136
+ end
@@ -1,3 +1,3 @@
1
1
  module BundleOutdatedFormatter
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundle_outdated_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - emsk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-15 00:00:00.000000000 Z
11
+ date: 2017-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: psych
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: thor
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -133,6 +147,7 @@ files:
133
147
  - exe/bof
134
148
  - lib/bundle_outdated_formatter.rb
135
149
  - lib/bundle_outdated_formatter/cli.rb
150
+ - lib/bundle_outdated_formatter/formatter.rb
136
151
  - lib/bundle_outdated_formatter/version.rb
137
152
  homepage: https://github.com/emsk/bundle_outdated_formatter
138
153
  licenses: