filetype 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/filetype.rb +15 -12
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea7cc215335d49eb8a449ee4f7896963256396e3dd82808977f946785623cfb5
4
- data.tar.gz: 62ebd38de6d7f69fea1da86ab071f16dfbb660822ff48cbc6b29f47cd7c03e62
3
+ metadata.gz: e1f383bb7d24cfa2687d6a0b884d14a0cc043edc65807ab09e514269e695aa3b
4
+ data.tar.gz: e507b06d44c40eaf2193ffdc7e15b7225c43b9e6ff4e3c9cf06d4a09f8f1f29b
5
5
  SHA512:
6
- metadata.gz: d83e7ac6df8cb28b3c3429190fcad96317cde1f82017828305828ffbb389d18524d1b90728685949b0a0d79afbddaa20419a0361604044f9ff375c923086c792
7
- data.tar.gz: 2da0a3ac276ab6c35e9fef4416616fa36b7d9738eab8ed192100ecdad16d81f7ece94a3e7d8c12710f3990839b8d44873cad66dede620687cb5de7906ae80a90
6
+ metadata.gz: f21e7981f237df5afebbae6d4f37b347e37784e4a654b91977d74e5e407d5a736e28e6256b5439c6692ffbbcbf927863b03d2213ec8abed1ff67ab8c1cf2d9ba
7
+ data.tar.gz: f084517910c9038fb545756e51ebe9a8ad2ca9206a13fac8c194b64380e7f8de1d3aa7a0a74ca75c762dd2626e5f5fadadda471d078fa1e0ccb42d0975d0f4de
data/lib/filetype.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Filetype
2
2
  module_function
3
3
 
4
- VERSION = '1.2.0'
4
+ VERSION = '1.2.1'
5
5
 
6
6
  FTYPES = {
7
7
  :actionscript => %w[ as mxml ],
@@ -72,16 +72,8 @@ module Filetype
72
72
  # Filetype.get('Rakefile') #=> :rake
73
73
  # @return [Symbol] The language found or nil
74
74
  def get(fname)
75
- fname = File.basename(fname)
76
75
  FTYPES.each do |ftype, rule|
77
- case rule
78
- when Array
79
- return ftype if rule.include? ext(fname)
80
- when Regexp
81
- return ftype if fname.match rule
82
- when String, Symbol
83
- return ftype if fname == rule.to_s
84
- end
76
+ return ftype if file_passes_rule?(fname, rule)
85
77
  end
86
78
  nil
87
79
  end
@@ -93,9 +85,8 @@ module Filetype
93
85
  # Filetype.all('foo.h') #=> [:c, :cpp, :objc]
94
86
  # @return [Array] The list of languages found
95
87
  def all(fname)
96
- fname = File.basename(fname)
97
88
  FTYPES.select do |ftype, rule|
98
- ftype if rule.is_a?(Array) && rule.include?(ext(fname))
89
+ ftype if file_passes_rule?(fname, rule)
99
90
  end.keys
100
91
  end
101
92
 
@@ -119,4 +110,16 @@ module Filetype
119
110
  ext = File.extname(fname)[1..-1]
120
111
  ext.downcase if ext
121
112
  end
113
+
114
+ def self.file_passes_rule?(fname, rule)
115
+ base_fname = File.basename(fname)
116
+ case rule
117
+ when Array
118
+ return rule.include? ext(base_fname)
119
+ when Regexp
120
+ return base_fname.match rule
121
+ when String, Symbol
122
+ return base_fname == rule.to_s
123
+ end
124
+ end
122
125
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filetype
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Jarvis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-30 00:00:00.000000000 Z
11
+ date: 2022-03-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Find a file type according to a filename or extension
14
14
  email: