pathname-common_prefix 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ae47d64dcca3740368520414d14a6a0f9cdefe01465068f67115a7305d5516a5
4
+ data.tar.gz: 194e3d63c660c1995d38c4c75625477c243b90aeebfa1c674ecadbf982355195
5
+ SHA512:
6
+ metadata.gz: 5b37102392bdb6cc48e421e9059c90fcc262bae69358a76d29a4e81ec121350ef5801fd38740f7a7716e52ffa58783f4fbc8323f8093a842f6a9f7bfb5b66593
7
+ data.tar.gz: 8d0b4f8b6af02ad27885a33f757f8612d9e439d31773e2eac963bcffa739e18e1f2ced0570778ff734d7fbeba9f1526c3c6098fe97a37a42205bc01cfacd79c7
data/README.markdown CHANGED
@@ -2,11 +2,15 @@ Pathname common_prefix
2
2
  ======================
3
3
 
4
4
  This file provides `Pathname.common_prefix` and `Pathname#common_prefix`
5
- which calcurate the common prefix in the passed paths.
5
+ which calculate the common prefix in the passed paths.
6
6
 
7
7
  Installation
8
8
  ------------
9
9
 
10
+ gem install pathname-common_prefix
11
+
12
+ or
13
+
10
14
  git clone git@github.com:KitaitiMakoto/pathname-common_prefix.git
11
15
  cd pathname-common_prefix
12
16
  ruby setup.rb
@@ -33,17 +37,27 @@ Usage
33
37
 
34
38
  Pathname.common_prefix(Pathname('/absolute/path'), Pathname('relative/path')) # => nil
35
39
 
40
+ ### String arguments
41
+
42
+ require 'pathname/common_prefix'
43
+
44
+ paths = %w[
45
+ path/to/somewhere
46
+ path/to/anywhere
47
+ ]
48
+
49
+ Pathname.common_prefix(*paths) # => #<Pathname:path/to>
50
+
51
+
36
52
  ### Instance method
37
53
 
38
54
  require 'pathname/common_prefix'
39
55
 
40
56
  base = Pathname('/path/to/base/file')
41
57
  other = Pathname('/path/to/other/file')
42
-
43
58
  base.common_prefix(other) # => <Pathname:/path/to>
44
59
 
45
60
  another = Pathname('/path/to-another/file')
46
-
47
61
  base.common_prefix(other, another) # => <Pathname:/path>
48
62
 
49
63
  ### Command-line tool
@@ -80,8 +94,8 @@ From file:
80
94
  $ common-prefix paths
81
95
  /path/to
82
96
 
83
- Contributor
84
- -----------
97
+ Contributors
98
+ ------------
85
99
 
86
100
  * [@kachick](https://github.com/kachick)
87
101
 
@@ -89,4 +103,4 @@ License
89
103
  -------
90
104
 
91
105
  This program is distributed under the Ruby's license.
92
- But `setup.rb` is distributed under the GNU LGPS license. See the file for more information.
106
+ But `setup.rb` is distributed under the GNU LGPL license. See the file for more information.
data/Rakefile CHANGED
@@ -1,7 +1,13 @@
1
1
  require 'rake/testtask'
2
2
  require 'rubygems/tasks'
3
+ require "steep"
3
4
 
4
- task :default => :test
5
+ task :default => [:test, :typecheck]
5
6
 
6
7
  Rake::TestTask.new
7
8
  Gem::Tasks.new
9
+
10
+ desc "Check type"
11
+ task :typecheck do
12
+ Steep::Drivers::Check.new(stdout: $stdout, stderr: $stderr).run
13
+ end
data/Steepfile ADDED
@@ -0,0 +1,29 @@
1
+ # D = Steep::Diagnostic
2
+ #
3
+ target :lib do
4
+ signature "sig"
5
+
6
+ check "lib" # Directory name
7
+ # check "Gemfile" # File name
8
+ # check "app/models/**/*.rb" # Glob
9
+ # ignore "lib/templates/*.rb"
10
+
11
+ library "pathname" # Standard libraries
12
+ # library "strong_json" # Gems
13
+
14
+ # configure_code_diagnostics(D::Ruby.default) # `default` diagnostics setting (applies by default)
15
+ # configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
16
+ # configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
17
+ # configure_code_diagnostics(D::Ruby.silent) # `silent` diagnostics setting
18
+ # configure_code_diagnostics do |hash| # You can setup everything yourself
19
+ # hash[D::Ruby::NoMethod] = :information
20
+ # end
21
+ end
22
+
23
+ # target :test do
24
+ # signature "sig", "sig-private"
25
+ #
26
+ # check "test"
27
+ #
28
+ # # library "pathname" # Standard libraries
29
+ # end
data/bin/common-prefix CHANGED
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'optparse'
3
+ require "rubygems/specification"
3
4
  require_relative '../lib/pathname/common_prefix'
4
5
 
5
6
  opt = OptionParser.new do |opt|
6
- opt.version = '0.0.1'
7
+ opt.version = Gem::Specification.load(File.join(__dir__, "../pathname-common_prefix.gemspec")).version
7
8
  opt.banner = <<EOB
8
9
  Usage: common-prefix
9
10
  Show prefix common to pathnames from standard input
@@ -13,7 +14,7 @@ EOB
13
14
  end
14
15
  opt.parse!
15
16
 
16
- paths = ARGF.lines.select {|line| line !~ /^$/}.collect(&:chomp)
17
+ paths = ARGF.each_line.select {|line| line !~ /^$/}.collect(&:chomp)
17
18
  begin
18
19
  puts Pathname.common_prefix(paths)
19
20
  rescue => err
@@ -3,21 +3,25 @@ require 'pathname'
3
3
  class Pathname
4
4
  class << self
5
5
  def common_prefix(*paths)
6
- return if paths.empty?
7
6
  paths.flatten!
7
+ return if paths.empty?
8
+ # @type var paths: NonEmptyArray[string | Pathname]
8
9
  Pathname(paths.pop).common_prefix(paths)
9
10
  end
10
11
  end
11
12
 
12
13
  def common_prefix(*others)
13
14
  others.flatten!
15
+ # @type var others: Array[string | Pathname]
14
16
  others.map! {|path| Pathname path}
17
+ # @type var others: Array[Pathname]
15
18
  enum_for(:ascend).find {|path|
16
- others.all?{|other|other.start_with?(path)}
19
+ # @type path: pathnamable
20
+ others.all? {|other|other.start_with?(path)}
17
21
  }
18
22
  end
19
23
 
20
- def start_with?(other)
21
- enum_for(:descend).include?(Pathname(other))
24
+ def start_with?(prefix)
25
+ enum_for(:descend).include?(Pathname(prefix))
22
26
  end
23
27
  end
@@ -1,11 +1,13 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'pathname-common_prefix'
3
- gem.version = '0.0.1'
3
+ gem.version = '0.0.2'
4
4
  gem.authors = ['KITAITI Makoto']
5
5
  gem.email = ['KitaitiMakoto@gmail.com']
6
- gem.description = 'This file provides `Pathname.common_prefix` and `Pathname#common_prefix` which calcurate the common prefix in the passed paths.'
7
- gem.summary = 'Calcurate prefix commont to some pathnames'
8
- gem.homepage = 'https://github.com/KitaitiMakoto/pathname-common_prefix'
6
+ gem.description = 'This file provides `Pathname.common_prefix` and `Pathname#common_prefix` which calculate the common prefix in the passed paths.'
7
+ gem.summary = 'Calculate prefix commont to some pathnames'
8
+ gem.homepage = 'https://gitlab.com/KitaitiMakoto/pathname-common_prefix'
9
+
10
+ gem.metadata["source_code_uri"] = "https://gitlab.com/KitaitiMakoto/pathname-common_prefix"
9
11
 
10
12
  gem.files = %w[
11
13
  lib/pathname/common_prefix.rb
@@ -14,6 +16,7 @@ Gem::Specification.new do |gem|
14
16
  README.markdown
15
17
  Rakefile setup.rb
16
18
  pathname-common_prefix.gemspec
19
+ Steepfile sig/pathname-common_prefix.rbs
17
20
  ]
18
21
  gem.executables = %w[common-prefix]
19
22
  gem.test_files = %w[test/test_common_prefix.rb]
@@ -0,0 +1,16 @@
1
+ # TypeProf 0.21.8
2
+
3
+ # Classes
4
+ class Pathname
5
+ def self.common_prefix: (*pathnamable_array paths) -> Pathname?
6
+ def common_prefix: (*pathnamable_array others) -> Pathname?
7
+ def start_with?: (pathnamable other) -> bool
8
+ end
9
+
10
+ type pathnamable = string | Pathname
11
+ type pathnamable_array = pathnamable | Array[pathnamable_array]
12
+
13
+ # Class just for type checking
14
+ class NonEmptyArray[T] < Array[T]
15
+ def pop: -> T
16
+ end
metadata CHANGED
@@ -1,18 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pathname-common_prefix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - KITAITI Makoto
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-30 00:00:00.000000000Z
11
+ date: 2023-12-24 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: This file provides `Pathname.common_prefix` and `Pathname#common_prefix`
15
- which calcurate the common prefix in the passed paths.
14
+ which calculate the common prefix in the passed paths.
16
15
  email:
17
16
  - KitaitiMakoto@gmail.com
18
17
  executables:
@@ -20,36 +19,37 @@ executables:
20
19
  extensions: []
21
20
  extra_rdoc_files: []
22
21
  files:
23
- - lib/pathname/common_prefix.rb
24
- - test/test_common_prefix.rb
25
- - bin/common-prefix
26
22
  - README.markdown
27
23
  - Rakefile
28
- - setup.rb
24
+ - Steepfile
25
+ - bin/common-prefix
26
+ - lib/pathname/common_prefix.rb
29
27
  - pathname-common_prefix.gemspec
30
- homepage: https://github.com/KitaitiMakoto/pathname-common_prefix
28
+ - setup.rb
29
+ - sig/pathname-common_prefix.rbs
30
+ - test/test_common_prefix.rb
31
+ homepage: https://gitlab.com/KitaitiMakoto/pathname-common_prefix
31
32
  licenses: []
32
- post_install_message:
33
+ metadata:
34
+ source_code_uri: https://gitlab.com/KitaitiMakoto/pathname-common_prefix
35
+ post_install_message:
33
36
  rdoc_options: []
34
37
  require_paths:
35
38
  - lib
36
39
  required_ruby_version: !ruby/object:Gem::Requirement
37
- none: false
38
40
  requirements:
39
- - - ! '>='
41
+ - - ">="
40
42
  - !ruby/object:Gem::Version
41
43
  version: '0'
42
44
  required_rubygems_version: !ruby/object:Gem::Requirement
43
- none: false
44
45
  requirements:
45
- - - ! '>='
46
+ - - ">="
46
47
  - !ruby/object:Gem::Version
47
48
  version: '0'
48
49
  requirements: []
49
- rubyforge_project:
50
- rubygems_version: 1.8.8
51
- signing_key:
52
- specification_version: 3
53
- summary: Calcurate prefix commont to some pathnames
50
+ rubygems_version: 3.5.3
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Calculate prefix commont to some pathnames
54
54
  test_files:
55
55
  - test/test_common_prefix.rb