churned 0.1.3 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54952fe9d2d35687446a55890d4dc6c207b434f72377d76b217254ee6e1a7291
4
- data.tar.gz: ebc1588dc974723ad004c7176bdf33506df91e92afc0a59ec38d04cb38f4c9a2
3
+ metadata.gz: bdbda526e18257f230ce6d34a512d719d34b77489d55f07099f1649bbaac337e
4
+ data.tar.gz: 72e9e1690105e3a38f28e37bb1802d2514f256545532e65346c5fc830cd48dca
5
5
  SHA512:
6
- metadata.gz: faa201fc3cf2d15bbac9367e672acce35a333b36bebac56eb574394b0d476ccdfe72fcf6b6550f783e222a13fb69569b05d1bec36d38d2d7a356c95823fa95ec
7
- data.tar.gz: 811dc8993d4da38c91862700ad362bb693ada1a9ce7cbfda0685ef0d3c8da39d404dc6e44788555a4675d3f4c0569e905d5fc5beeb38a78404b5cb120b2c6d1d
6
+ metadata.gz: ff3b3edfa9f85ca918e8cb2fe5960cec0ae50e3000a237334dff4ed12e721b39c37c54f8f5ead25f794fcbbc01f8de417649faee0da0f8bea813c5a3707f7d00
7
+ data.tar.gz: d4bbd9cbcb1c3c8d66bc15daa6f540cc834e628772d18e71c29ee33d4fb5c9af0e960117a1408d3d712bb1023b176a2704534379a8c8c4e6d8b2f9a6ec86396a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- churned (0.1.3)
4
+ churned (0.2.0)
5
5
  activerecord (~> 6.1)
6
6
  pry
7
7
  sqlite3
@@ -28,7 +28,7 @@ GEM
28
28
  concurrent-ruby (1.1.9)
29
29
  diff-lcs (1.4.4)
30
30
  equatable (0.7.0)
31
- i18n (1.8.10)
31
+ i18n (1.8.11)
32
32
  concurrent-ruby (~> 1.0)
33
33
  method_source (1.0.0)
34
34
  minitest (5.14.4)
@@ -62,7 +62,7 @@ GEM
62
62
  tzinfo (2.0.4)
63
63
  concurrent-ruby (~> 1.0)
64
64
  wisper (2.0.1)
65
- zeitwerk (2.4.2)
65
+ zeitwerk (2.5.1)
66
66
 
67
67
  PLATFORMS
68
68
  ruby
data/bin/console CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ ENV["TTY_ENV"] = "development"
3
4
  require "bundler/setup"
4
5
  require "churned"
5
6
 
data/bin/debug ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV["TTY_ENV"] = "development"
4
+ require "bundler/setup"
5
+ require "churned"
6
+
7
+ Signal.trap('INT') do
8
+ warn("\n#{caller.join("\n")}: interrupted")
9
+ exit(1)
10
+ end
11
+
12
+ begin
13
+ Churned::CLI.start
14
+ rescue Churned::CLI::Error => err
15
+ puts "ERROR: #{err.message}"
16
+ exit 1
17
+ end
@@ -0,0 +1,19 @@
1
+ require "active_record"
2
+ require "sqlite3"
3
+
4
+ module Churned
5
+ def db_config
6
+ {
7
+ "production" => { "database_name" => ".churned/db.sqlite" },
8
+ "test" => { "database_name" => ".churned/db_test.sqlite" },
9
+ "development" => { "database_name" => ".churned/db_development.sqlite" },
10
+ }
11
+ end
12
+
13
+ def database
14
+ db_config[ENV["TTY_ENV"]]["database_name"]
15
+ end
16
+ module_function :db_config, :database
17
+ end
18
+
19
+ ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: Churned.database)
data/exe/churned CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ ENV["TTY_ENV"] = "production"
5
+
4
6
  lib_path = File.expand_path('../lib', __dir__)
5
7
  $:.unshift(lib_path) if !$:.include?(lib_path)
6
8
  require 'churned'
data/lib/churned/cli.rb CHANGED
@@ -26,7 +26,6 @@ module Churned
26
26
  invoke :help, ['console']
27
27
  else
28
28
  require_relative 'commands/console'
29
- require 'pry'
30
29
  Churned::Commands::Console.new(options).execute
31
30
  end
32
31
  end
@@ -18,6 +18,11 @@ module Churned
18
18
  )
19
19
  end
20
20
 
21
+ def db
22
+ require_relative 'commands/db'
23
+ Commands::DB
24
+ end
25
+
21
26
  # The external commands runner
22
27
  #
23
28
  # @see http://www.rubydoc.info/gems/tty-command
@@ -10,6 +10,7 @@ module Churned
10
10
  end
11
11
 
12
12
  def execute(input: $stdin, output: $stdout)
13
+ require "pry"
13
14
  Pry.start
14
15
  end
15
16
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../command'
4
+
5
+ module Churned
6
+ module Commands
7
+ module DB
8
+ class Create < Churned::Command
9
+ def initialize(options)
10
+ @options = options
11
+ end
12
+
13
+ def self.execute
14
+ new({}).execute(input: $stdin, output: $stdout)
15
+ end
16
+
17
+ def execute(input: $stdin, output: $stdout)
18
+ generator.create_dir(".churned")
19
+
20
+ ActiveRecord::Schema.define do
21
+ create_table :commits, force: true do |t|
22
+ t.string :sha
23
+ t.string :author
24
+ t.date :author_date
25
+ end
26
+
27
+ create_table :file_changes, force: true do |t|
28
+ t.references :commit
29
+ t.string :pathname
30
+ t.integer :additions, default: 0
31
+ t.integer :deletions, default: 0
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../command'
4
+
5
+ module Churned
6
+ module Commands
7
+ module DB
8
+ class Load < Churned::Command
9
+ def initialize(options)
10
+ @options = options
11
+ end
12
+
13
+ def self.execute(filename)
14
+ new({}).execute(filename, input: $stdin, output: $stdout)
15
+ end
16
+
17
+ def execute(filename, input: $stdin, output: $stdout)
18
+ IO.read(filename).split("\n\n").each do |description|
19
+ sha, date, author, *numstats = description.split("\n")
20
+
21
+ commit = Commit.new(sha: sha, author_date: date, author: author)
22
+
23
+ numstats.each do |numstat|
24
+ additions, deletions, pathname = numstat.split("\t")
25
+ commit.file_changes.build(additions: additions, deletions: deletions, pathname: pathname)
26
+ end
27
+
28
+ commit.save
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+ require_relative 'db/load'
5
+ require_relative 'db/create'
6
+
7
+ module Churned
8
+ module Commands
9
+ module DB
10
+ module_function
11
+
12
+ def create
13
+ Create.execute
14
+ end
15
+
16
+ def load(filename)
17
+ Load.execute(filename)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -9,44 +9,10 @@ module Churned
9
9
  @options = options
10
10
  end
11
11
 
12
- def execute(input: $stdin, output: $stdout)
13
- generator.create_dir(".churned")
14
- generator.remove_file ".churned/database"
15
-
16
- ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ".churned/database")
17
-
18
- ActiveRecord::Schema.define do
19
- create_table :commits, force: true do |t|
20
- t.string :sha
21
- t.string :author
22
- t.date :author_date
23
- end
24
-
25
- create_table :file_changes, force: true do |t|
26
- t.references :commit
27
- t.string :pathname
28
- t.integer :additions
29
- t.integer :deletions
30
- end
31
- end
32
-
33
- command.run("git log --no-merges --pretty=format:'%H%n%ad%n%ae' --numstat --since=1.years > .churned/hashes.txt")
34
-
35
- IO.read('.churned/hashes.txt').split("\n\n").each do |description|
36
- lines = description.split("\n")
37
-
38
- sha = lines.shift
39
- date = lines.shift
40
- author = lines.shift
41
- commit = Commit.new(sha: sha, author_date: date, author: author)
42
-
43
- lines.each do |numstat|
44
- additions, deletions, pathname = numstat.split("\t")
45
- commit.file_changes.build(additions: additions, deletions: deletions, pathname: pathname)
46
- end
47
-
48
- commit.save
49
- end
12
+ def execute(filename = ".churned/hashes.txt", input: $stdin, output: $stdout)
13
+ db.create
14
+ command.run("git log --no-merges --pretty=format:'%H%n%ad%n%ae' --numstat --since=1.years > #{filename}")
15
+ db.load(filename)
50
16
  end
51
17
  end
52
18
  end
@@ -0,0 +1 @@
1
+ #
@@ -0,0 +1 @@
1
+ #
@@ -1,3 +1,3 @@
1
1
  module Churned
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/churned.rb CHANGED
@@ -1,10 +1,7 @@
1
- require "active_record"
2
- require "sqlite3"
1
+ require_relative "../config/database"
3
2
  require "churned/version"
4
3
  require "churned/cli"
5
4
 
6
- ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ".churned/database")
7
-
8
5
  module Churned
9
6
  class Commit < ActiveRecord::Base
10
7
  has_many :file_changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: churned
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Barret
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-19 00:00:00.000000000 Z
11
+ date: 2021-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -125,17 +125,24 @@ files:
125
125
  - README.md
126
126
  - Rakefile
127
127
  - bin/console
128
+ - bin/debug
128
129
  - bin/setup
129
130
  - churned.gemspec
131
+ - config/database.rb
130
132
  - exe/churned
131
133
  - lib/churned.rb
132
134
  - lib/churned/cli.rb
133
135
  - lib/churned/command.rb
134
136
  - lib/churned/commands/.gitkeep
135
137
  - lib/churned/commands/console.rb
138
+ - lib/churned/commands/db.rb
139
+ - lib/churned/commands/db/create.rb
140
+ - lib/churned/commands/db/load.rb
136
141
  - lib/churned/commands/install.rb
137
142
  - lib/churned/templates/.gitkeep
138
143
  - lib/churned/templates/console/.gitkeep
144
+ - lib/churned/templates/db/create/.gitkeep
145
+ - lib/churned/templates/db/load/.gitkeep
139
146
  - lib/churned/templates/install/.gitkeep
140
147
  - lib/churned/version.rb
141
148
  homepage: https://github.com/AlexB52/churned