gemat 0.1.3 → 0.1.4

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
  SHA256:
3
- metadata.gz: fff413b0bfd43a7b693a244946e15ede730a479ec4be7260605e71d4001cc72a
4
- data.tar.gz: 325d18312000d035eda2c45c96feeab44245515e75de9ff6139e7f72661114e8
3
+ metadata.gz: d8aaec3acaf9aba89e198cf7077ea42527378af2ed240a2afd9569a463ffb11c
4
+ data.tar.gz: b1848af9dd9395a6a1e8b10615758da31fbbb8273fe08780c00d55393445cc6f
5
5
  SHA512:
6
- metadata.gz: bfff75358ea7333d62a15ea928c3d2e4e65742097cde1282ae2f8e1c3113e7480773d0f51dfc9b4619fd75f5c4d332d945313b6b170144be6444a9d3ac23dc86
7
- data.tar.gz: ae0556e9407890301bcd97692aad4008da235ea943a45e5bb9de28768e9ac5de2628b42498e7f46fe3cf2e0d982f16d212331a30e4c74e622084694f8f17b992
6
+ metadata.gz: c1ba3ce74b81c32c70ced331101bc9345eebd57b1481f8f28743c021076499cc136d3dae6b1aeb5fd79355f860a18b6ffaa5bfa6b065fb5a6fd59295c1fcd1f4
7
+ data.tar.gz: 7d780cfafb27dafd2becf3043337f4779aac46a9d17364179b9f15c9e20d47f505ed7067a05a7171d085c23a2144b6eb824586641ba280c90a048b02fe99f8d5
data/lib/csv_formatter.rb CHANGED
@@ -1,33 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'csv'
4
-
5
3
  module Gemat
6
- class CsvFormatter
7
- def initialize(gems, output = nil)
8
- @gems = gems
9
- @output = output
10
- @rows = []
11
- gen_rows
12
- end
13
-
14
- def to_csv
15
- if @output
16
- CSV.open(@output, 'w') do |csv|
17
- @rows.each { |row| csv << row }
18
- end
19
- else
20
- print "\n\n"
21
- @rows.each { |row| print row.to_csv }
22
- end
23
- end
24
-
4
+ class CsvFormatter < Formatter
25
5
  private
26
6
 
27
7
  def gen_rows
28
- @rows << ['gem', 'Repo URL']
8
+ @rows << @columns.map(&:column_name).join(',')
29
9
  @gems.each do |gem|
30
- @rows << [gem.name, gem.repo_url]
10
+ @rows << @columns.map { |dsl| dsl.call(gem) }.join(',')
31
11
  end
32
12
  end
33
13
  end
data/lib/fetcher.rb CHANGED
@@ -11,14 +11,16 @@ module Gemat
11
11
 
12
12
  def run
13
13
  pb = ProgressBar.create(total: @dsl.dependencies.length)
14
- @dsl.dependencies.each do |gem|
14
+ @dsl.dependencies.each_with_index do |gem, idx|
15
15
  sleep 0.1
16
16
  pb.increment
17
17
 
18
18
  response = fetch(gem)
19
19
  next unless response
20
20
 
21
- @gems << Gem.new(response)
21
+ gem = Gem.new(response)
22
+ gem.index = idx
23
+ @gems << gem
22
24
  end
23
25
  end
24
26
 
data/lib/formatter.rb ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gemat
4
+ class Formatter
5
+ def initialize(gems, columns, write_path: nil)
6
+ @gems = gems
7
+ @columns = columns
8
+ @write_path = write_path
9
+ @rows = []
10
+ gen_rows
11
+ end
12
+
13
+ def run
14
+ if @write_path
15
+ File.open(@write_path, 'w') do |file|
16
+ each_write(@rows) { |string| file << string }
17
+ end
18
+ else
19
+ print "\n\n"
20
+ each_write(@rows) { |string| print string }
21
+ print "\n"
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def each_write(rows, &proc)
28
+ rows.each do |row|
29
+ proc.call(row)
30
+ proc.call("\n")
31
+ end
32
+ end
33
+ end
34
+ end
data/lib/gem.rb CHANGED
@@ -2,8 +2,11 @@
2
2
 
3
3
  module Gemat
4
4
  class Gem
5
+ attr_accessor :index
6
+
5
7
  def initialize(response)
6
8
  @response = response
9
+ @index = 0
7
10
  end
8
11
 
9
12
  def name
data/lib/gemat/cli.rb CHANGED
@@ -1,19 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'thor'
4
-
5
3
  module Gemat
6
4
  class Cli < Thor
7
5
  desc 'csv', 'export Gemfile to CSV file'
8
- method_options input: :string, output: :string
6
+ method_options input: :string, output: :string, columns: :array
9
7
  def csv
10
- Gemat.run(options) { |gems| CsvFormatter.new(gems, options[:output]).to_csv }
8
+ command(options, __method__)
11
9
  end
12
10
 
13
11
  desc 'md', 'export Gemfile to markdown'
14
- method_options input: :string, output: :string
12
+ method_options input: :string, output: :string, columns: :array
15
13
  def md
16
- Gemat.run(options) { |gems| MdFormatter.new(gems, options[:output]).to_md }
14
+ command(options, __method__)
15
+ end
16
+
17
+ no_tasks do
18
+ def command(options, method_name)
19
+ klass = "Gemat::#{method_name.capitalize}Formatter"
20
+ Gemat.run(options) do |gems, columns|
21
+ Object.const_get(klass).new(gems, columns, write_path: options[:output]).run
22
+ end
23
+ end
17
24
  end
18
25
  end
19
26
  end
data/lib/gemat/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gemat
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
data/lib/gemat.rb CHANGED
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'bundler'
3
4
  require 'httpclient'
4
5
  require 'json'
5
6
  require 'ruby-progressbar'
7
+ require 'thor'
6
8
 
7
9
  require_relative 'in_dsl'
10
+ require_relative 'out_dsl'
8
11
  require_relative 'fetcher'
9
12
  require_relative 'gem'
13
+ require_relative 'formatter'
10
14
  require_relative 'csv_formatter'
11
15
  require_relative 'md_formatter'
12
16
  require_relative 'gemat/version'
@@ -18,9 +22,10 @@ module Gemat
18
22
  class Gemat
19
23
  def self.run(options = {}, &block)
20
24
  dsl = InDsl.new(options[:input])
25
+ outdsls = OutDsl.create(options[:columns])
21
26
  fetcher = Fetcher.new(dsl)
22
27
  fetcher.run
23
- block.call(fetcher.gems)
28
+ block.call(fetcher.gems, outdsls)
24
29
  end
25
30
  end
26
31
  end
data/lib/in_dsl.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler'
4
-
5
3
  module Gemat
6
4
  class InDsl
7
5
  attr_accessor :dependencies, :sources, :git_sources, :groups, :gemfiles
data/lib/md_formatter.rb CHANGED
@@ -1,39 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'logger'
4
-
5
3
  module Gemat
6
- class MdFormatter
7
- def initialize(gems, output = nil)
8
- @gems = gems
9
- @output = output
10
- @rows = []
11
- gen_rows
12
- end
13
-
14
- def to_md
15
- if @output
16
- File.open(@output, 'w') { |file| each_write(@rows) { |string| file.<< string } }
17
- else
18
- print "\n\n"
19
- each_write(@rows) { |string| print string }
20
- end
21
- end
22
-
4
+ class MdFormatter < Formatter
23
5
  private
24
6
 
25
7
  def gen_rows
26
- @rows << '| gem | Repo URL |'
27
- @rows << '| ---- | ---- |'
8
+ @rows << "| #{@columns.map(&:column_name).join(' | ')} |"
9
+ @rows << "| #{Array.new(@columns.length, '----').join(' | ')} |"
28
10
  @gems.each do |gem|
29
- @rows << "| #{gem.name} | #{gem.repo_url} |"
30
- end
31
- end
32
-
33
- def each_write(rows, &proc)
34
- rows.each do |row|
35
- proc.call(row)
36
- proc.call("\n")
11
+ @rows << "| #{@columns.map { |dsl| dsl.call(gem) }.join(' | ')} |"
37
12
  end
38
13
  end
39
14
  end
data/lib/out_dsl.rb ADDED
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gemat
4
+ class OutDsl
5
+ INDEX = 'index'
6
+ NAME = 'name'
7
+ REPO_URL = 'repo_url'
8
+ DEFAULT_COLUMNS = [INDEX, NAME, REPO_URL].freeze
9
+
10
+ attr_accessor :column_name
11
+
12
+ def self.new_by_array(columns)
13
+ columns.map { |column| new(column) }
14
+ end
15
+
16
+ def self.create(columns)
17
+ if columns
18
+ new_by_array(columns)
19
+ else
20
+ new_by_array(DEFAULT_COLUMNS)
21
+ end
22
+ end
23
+
24
+ def initialize(column_name)
25
+ @column_name = column_name
26
+
27
+ set_lambda
28
+ end
29
+
30
+ def call(gem)
31
+ @lambda.call(gem)
32
+ end
33
+
34
+ def set_lambda
35
+ case @column_name
36
+ when NAME
37
+ @lambda = name
38
+ when REPO_URL
39
+ @lambda = repo_url
40
+ when INDEX
41
+ @lambda = index
42
+ end
43
+ end
44
+
45
+ def name
46
+ ->(gem) { gem.name }
47
+ end
48
+
49
+ def repo_url
50
+ ->(gem) { gem.repo_url }
51
+ end
52
+
53
+ def index
54
+ ->(gem) { gem.index }
55
+ end
56
+ end
57
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - kijimaD
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-27 00:00:00.000000000 Z
11
+ date: 2021-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -63,12 +63,14 @@ files:
63
63
  - exe/gemat
64
64
  - lib/csv_formatter.rb
65
65
  - lib/fetcher.rb
66
+ - lib/formatter.rb
66
67
  - lib/gem.rb
67
68
  - lib/gemat.rb
68
69
  - lib/gemat/cli.rb
69
70
  - lib/gemat/version.rb
70
71
  - lib/in_dsl.rb
71
72
  - lib/md_formatter.rb
73
+ - lib/out_dsl.rb
72
74
  homepage: https://github.com/kijimaD/gemat
73
75
  licenses:
74
76
  - GPL3