fedux_org-stdlib 0.9.8 → 0.10.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
  SHA1:
3
- metadata.gz: 00f1ef63f383a5360c23e10f1a7b4280e7778a59
4
- data.tar.gz: 8a6a0e335c55e1dfbbb40328a463d81656dedbd4
3
+ metadata.gz: 142074fe00300790fa28656899176829d9e6e60b
4
+ data.tar.gz: 9052f89fe52d1d5226a6ebcad78e37513dcb8858
5
5
  SHA512:
6
- metadata.gz: ce299f4960290869a15f033ebc848cda1cffa27aa82756ac5b241af246fe7beef19744926495704578d11f28701c32b6ccecca41d128fa136939a89ce6db2974
7
- data.tar.gz: d08adb8405bc1b56604d66b0a61af57b1346f9ef57be64203339241c40f9eac05664f8428424d7dff3adb2a61daa06caee7cbc9a62dc95c6d693eba1b50c69e7
6
+ metadata.gz: 9df9eae8d9e2e5cb8f07ef3cec90f98618e70aea181116099c265a4d290c526b856f26c89719a783908093fbf804d53aad98b301e567f9bb5d3cb5c335719909
7
+ data.tar.gz: 60bdbdcef44d8c1fdad4792021ba98b1b2eb445d6d6b69bbef6a53427508894d7c41348243936b924262a294305aab47e8c6e5071ed7365dd6ca1d46c4e79308
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fedux_org-stdlib (0.9.7)
4
+ fedux_org-stdlib (0.10.0)
5
5
  activesupport
6
6
 
7
7
  PATH
@@ -1,6 +1,7 @@
1
1
  AllCops:
2
2
  Exclude:
3
- - spec/examples/**/*.rb
3
+ - spec/examples/**/*.rb
4
+ - fixtures/**/*.rb
4
5
 
5
6
  # Offense count: 230
6
7
  # Configuration parameters: AllowURI.
@@ -270,7 +270,7 @@ module FeduxOrgStdlib
270
270
 
271
271
  # Return configuration resetted to defaults
272
272
  def defaults
273
- config = self.dup
273
+ config = dup
274
274
  config.clear
275
275
 
276
276
  config
@@ -280,8 +280,8 @@ module FeduxOrgStdlib
280
280
  options_to_check = known_options.delete_if { |o| !keys.blank? && !keys.map(&:to_sym).include?(o) }.sort
281
281
 
282
282
  options_to_check.each_with_object({}) do |e, a|
283
- next if remove_blank && self.public_send(e).blank?
284
- a[e] = self.public_send(e)
283
+ next if remove_blank && public_send(e).blank?
284
+ a[e] = public_send(e)
285
285
  end
286
286
  end
287
287
 
@@ -303,7 +303,6 @@ module FeduxOrgStdlib
303
303
  return
304
304
  end
305
305
 
306
-
307
306
  files = if merge_files
308
307
  self.files
309
308
  else
@@ -427,10 +426,10 @@ module FeduxOrgStdlib
427
426
  (methods | instance_methods | private_methods | private_instance_methods) - (Class.methods | Class.private_methods) | [:to_s]
428
427
  end
429
428
 
430
- #def method_missing(*args, &block)
429
+ # def method_missing(*args, &block)
431
430
  # $stderr.puts "Please check if you have defined an option for #{args.first}."
432
431
 
433
432
  # super
434
- #end
433
+ # end
435
434
  end
436
435
  end
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ require 'fedux_org_stdlib/core_ext/file/which'
3
+
4
+ module FeduxOrgStdlib
5
+ class CommandFinder
6
+ private
7
+
8
+ attr_reader :search_paths, :alternatives
9
+
10
+ public
11
+
12
+ # Finds path to command
13
+ #
14
+ # It also considers other executables for one command
15
+ #
16
+ # @param [String, Array] alternatives
17
+ # The executables to be used
18
+ #
19
+ # @param [String, Array] search_paths
20
+ # The search path as multiple paths as array or string where single
21
+ # search paths are concatenated via ':'
22
+ def initialize(alternatives:, search_paths:)
23
+ @alternatives = Array(alternatives)
24
+ @search_paths = Array(search_paths)
25
+ end
26
+
27
+ # Find path to command
28
+ def path
29
+ alternatives.each do |e|
30
+ next unless path = File.which(e, search_paths.join(':'))
31
+
32
+ return path
33
+ end
34
+
35
+ nil
36
+ end
37
+
38
+ # Return known commands
39
+ def known_commands
40
+ @alternatives
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,76 @@
1
+ # encoding: utf-8
2
+ require 'rbconfig'
3
+ require 'win32/file' if File::ALT_SEPARATOR
4
+
5
+ require 'fedux_org_stdlib/require_files'
6
+ require_library %w(active_support/core_ext/object/blank)
7
+
8
+ # File class
9
+ class File
10
+ if File::ALT_SEPARATOR
11
+ MSWINDOWS = true
12
+ if ENV['PATHEXT']
13
+ WIN32EXTS = ('.{' + ENV['PATHEXT'].tr(';', ',').tr('.', '') + '}').downcase
14
+ else
15
+ WIN32EXTS = '.{exe,com,bat}'
16
+ end
17
+ else
18
+ MSWINDOWS = false
19
+ end
20
+
21
+ class << self
22
+ # Search program in search path
23
+ #
24
+ # @param [String] program
25
+ # The program to look for
26
+ #
27
+ # @param [String] path
28
+ # The search path
29
+ #
30
+ # @return [String, NilClass]
31
+ # If the program could be found in search path, the full path will be
32
+ # returned otherwise `#which` returns nil.
33
+ def which(program, path = ENV['PATH'])
34
+ fail ArgumentError, path if path.blank?
35
+
36
+ return nil if program.blank?
37
+
38
+ # Bail out early if an absolute path is provided.
39
+ if program =~ %r{^/|^[a-z]:[/]}i
40
+ program += WIN32EXTS if MSWINDOWS && File.extname(program).blank?
41
+ found = Dir[program].first
42
+ if found && File.executable?(found) && !File.directory?(found)
43
+ return found
44
+ else
45
+ return nil
46
+ end
47
+ end
48
+
49
+ # Iterate over each path glob the dir + program.
50
+ path.split(File::PATH_SEPARATOR).each do |dir|
51
+ dir = File.expand_path(dir)
52
+
53
+ next unless File.exist?(dir) # In case of bogus second argument
54
+ file = File.join(dir, program)
55
+
56
+ # Dir[] doesn't handle backslashes properly, so convert them. Also, if
57
+ # the program name doesn't have an extension, try them all.
58
+ if MSWINDOWS
59
+ file = file.tr('\\', '/')
60
+ file += WIN32EXTS if File.extname(program).blank?
61
+ end
62
+
63
+ found = Dir[file].first
64
+
65
+ next if !found || !File.executable?(found) || File.directory?(found)
66
+
67
+ # Convert all forward slashes to backslashes if supported
68
+ found.tr!(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR
69
+
70
+ return found
71
+ end
72
+
73
+ nil
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ require 'fedux_org_stdlib/command_finder'
3
+
4
+ module FeduxOrgStdlib
5
+ # Look for editor in PATH
6
+ #
7
+ # @example Usage
8
+ #
9
+ # editor = Editor.new
10
+ # editor.path #=> /usr/bin/vim if vim exists at /usr/bin
11
+ class Editor < CommandFinder
12
+ def initialize(editors: %w(vim vi emacs nano), search_paths: ENV['PATH'].split(/:/))
13
+ super alternatives: editors, search_paths: search_paths
14
+ end
15
+ end
16
+ end
@@ -5,6 +5,7 @@ require 'fedux_org_stdlib/logging/logger'
5
5
  require_library %w(pathname)
6
6
 
7
7
  module FeduxOrgStdlib
8
+ # Look for file recursively
8
9
  class RecursiveFileFinder
9
10
  # Create a new instance of finder
10
11
  #
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # FeduxOrgStdlib
3
3
  module FeduxOrgStdlib
4
- VERSION = '0.9.8'
4
+ VERSION = '0.10.0'
5
5
  end
@@ -545,14 +545,9 @@ RSpec.describe AppConfig do
545
545
  config_klass = Class.new(AppConfig) do
546
546
  option :opt1, 'test1'
547
547
 
548
- option :opt2, [
549
- 'test2',
550
- 'test2',
551
- ]
548
+ option :opt2, %w(test2 test2)
552
549
 
553
- option :opt3, {
554
- test3: 'value3'
555
- }
550
+ option :opt3, test3: 'value3'
556
551
 
557
552
  def _class_name
558
553
  'TestConfig'
@@ -567,10 +562,10 @@ RSpec.describe AppConfig do
567
562
  expect(config.to_h).to eq(
568
563
  opt1: 'test1',
569
564
  opt2: %w(
570
- test2
571
- test2
565
+ test2
566
+ test2
572
567
  ),
573
- opt3: {
568
+ opt3: {
574
569
  test3: 'value3'
575
570
  }
576
571
  )
@@ -580,14 +575,9 @@ RSpec.describe AppConfig do
580
575
  config_klass = Class.new(AppConfig) do
581
576
  option :opt1, 'test1'
582
577
 
583
- option :opt2, [
584
- 'test2',
585
- 'test2',
586
- ]
578
+ option :opt2, %w(test2 test2)
587
579
 
588
- option :opt3, {
589
- test3: 'value3'
590
- }
580
+ option :opt3, test3: 'value3'
591
581
 
592
582
  def _class_name
593
583
  'TestConfig'
@@ -608,14 +598,9 @@ RSpec.describe AppConfig do
608
598
  config_klass = Class.new(AppConfig) do
609
599
  option :opt1, 'test1'
610
600
 
611
- option :opt2, [
612
- 'test2',
613
- 'test2',
614
- ]
601
+ option :opt2, %w(test2 test2)
615
602
 
616
- option :opt3, {
617
- test3: 'value3'
618
- }
603
+ option :opt3, test3: 'value3'
619
604
 
620
605
  def _class_name
621
606
  'TestConfig'
@@ -660,14 +645,9 @@ RSpec.describe AppConfig do
660
645
  config_klass = Class.new(AppConfig) do
661
646
  option :opt1, 'test1'
662
647
 
663
- option :opt2, [
664
- 'test2',
665
- 'test2',
666
- ]
648
+ option :opt2, %w(test2 test2)
667
649
 
668
- option :opt3, {
669
- test3: 'value3'
670
- }
650
+ option :opt3, test3: 'value3'
671
651
 
672
652
  def _class_name
673
653
  'TestConfig'
@@ -694,14 +674,9 @@ RSpec.describe AppConfig do
694
674
  config_klass = Class.new(AppConfig) do
695
675
  option :opt1, 'test1'
696
676
 
697
- option :opt2, [
698
- 'test2',
699
- 'test2',
700
- ]
677
+ option :opt2, %w(test2 test2)
701
678
 
702
- option :opt3, {
703
- test3: 'value3'
704
- }
679
+ option :opt3, test3: 'value3'
705
680
 
706
681
  def _class_name
707
682
  'TestConfig'
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'fedux_org_stdlib/command_finder'
4
+
5
+ RSpec.describe FeduxOrgStdlib::CommandFinder do
6
+ context '#path' do
7
+ it 'finds command in given order' do
8
+ touch_file 'command.sh'
9
+ filesystem_permissions '0755', 'command.sh'
10
+
11
+ editor = CommandFinder.new alternatives: %w(command.sh), search_paths: absolute_path('.')
12
+ expect(editor.path).to eq absolute_path('command.sh')
13
+ end
14
+
15
+ it 'returns nil if no command can be found' do
16
+ editor = CommandFinder.new alternatives: %w(command.sh), search_paths: absolute_path('.')
17
+ expect(editor.path).to be nil
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+
3
+ require 'fedux_org_stdlib/core_ext/file/which'
4
+
5
+ RSpec.describe 'File' do
6
+ around :example do |example|
7
+ with_env 'PATH' => absolute_path('.') do
8
+ example.run
9
+ end
10
+ end
11
+
12
+ context '#which' do
13
+ it 'returns path to command' do
14
+ touch_file 'vim'
15
+ filesystem_permissions '0755', 'vim'
16
+
17
+ expect(File.which('vim')).to eq absolute_path('vim')
18
+ end
19
+
20
+ it 'uses a different search path' do
21
+ touch_file 'vim'
22
+ filesystem_permissions '0755', 'vim'
23
+ expect(File.which('vim', absolute_path('.'))).to eq absolute_path('vim')
24
+ end
25
+
26
+ it 'returns nil if command could not be found' do
27
+ expect(File.which('vim')).to be nil
28
+ end
29
+
30
+ it 'returns nil if command is not executable' do
31
+ touch_file 'vim'
32
+ filesystem_permissions '0644', 'vim'
33
+ expect(File.which('vim')).to be nil
34
+ end
35
+
36
+ it 'returns nil if command is not a file' do
37
+ create_dir 'vim'
38
+ expect(File.which('vim')).to be nil
39
+ end
40
+
41
+ it 'supports ~' do
42
+ with_env 'HOME' => absolute_path('.') do
43
+ touch_file 'vim'
44
+ filesystem_permissions '0755', 'vim'
45
+ expect(File.which('vim', '~/')).to eq absolute_path('vim')
46
+ end
47
+ end
48
+
49
+ it 'returns nil if command path is blank' do
50
+ expect(File.which('')).to eq nil
51
+ expect(File.which(nil)).to eq nil
52
+ expect(File.which([])).to eq nil
53
+ end
54
+
55
+ it 'fails if search path is blank' do
56
+ expect { File.which('vim', '') }.to raise_error ArgumentError
57
+ expect { File.which('vim', nil) }.to raise_error ArgumentError
58
+ expect { File.which('vim', []) }.to raise_error ArgumentError
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'fedux_org_stdlib/editor'
4
+
5
+ RSpec.describe FeduxOrgStdlib::Editor do
6
+ around :example do |example|
7
+ with_env 'PATH' => absolute_path('.') do
8
+ example.run
9
+ end
10
+ end
11
+
12
+ context '#path' do
13
+ let(:editor) { Editor.new }
14
+
15
+ Editor.new.known_commands.each do |c|
16
+ it "finds editor #{c}" do
17
+ touch_file c
18
+ filesystem_permissions '0755', c
19
+ expect(editor.path).to eq absolute_path(c)
20
+ end
21
+ end
22
+
23
+ it 'changes search path' do
24
+ touch_file 'vim'
25
+ filesystem_permissions '0755', 'vim'
26
+
27
+ editor = Editor.new search_paths: absolute_path('.')
28
+ expect(editor.path).to eq absolute_path('vim')
29
+ end
30
+
31
+ it 'changes default editors' do
32
+ touch_file 'vi'
33
+ filesystem_permissions '0755', 'vi'
34
+
35
+ editor = Editor.new editors: %w(vi)
36
+ expect(editor.path).to eq absolute_path('vi')
37
+ end
38
+
39
+ it 'returns nil if no editor can be found' do
40
+ editor = Editor.new
41
+ expect(editor.path).to be nil
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fedux_org-stdlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Meyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-04 00:00:00.000000000 Z
11
+ date: 2014-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -62,8 +62,10 @@ files:
62
62
  - lib/fedux_org_stdlib/command/command_result.rb
63
63
  - lib/fedux_org_stdlib/command/run_command.rb
64
64
  - lib/fedux_org_stdlib/command/which.rb
65
+ - lib/fedux_org_stdlib/command_finder.rb
65
66
  - lib/fedux_org_stdlib/core_ext/array.rb
66
67
  - lib/fedux_org_stdlib/core_ext/array/list.rb
68
+ - lib/fedux_org_stdlib/core_ext/file/which.rb
67
69
  - lib/fedux_org_stdlib/core_ext/hash.rb
68
70
  - lib/fedux_org_stdlib/core_ext/hash/list.rb
69
71
  - lib/fedux_org_stdlib/core_ext/hash/options.rb
@@ -73,6 +75,7 @@ files:
73
75
  - lib/fedux_org_stdlib/core_ext/string/underline.rb
74
76
  - lib/fedux_org_stdlib/directory_finder.rb
75
77
  - lib/fedux_org_stdlib/directory_finder/exceptions.rb
78
+ - lib/fedux_org_stdlib/editor.rb
76
79
  - lib/fedux_org_stdlib/environment.rb
77
80
  - lib/fedux_org_stdlib/file_finder.rb
78
81
  - lib/fedux_org_stdlib/file_finder/exceptions.rb
@@ -172,12 +175,15 @@ files:
172
175
  - spec/colors/html_color_spec.rb
173
176
  - spec/command/run_command_spec.rb
174
177
  - spec/command/which_spec.rb
178
+ - spec/command_finder_spec.rb
175
179
  - spec/core_ext/array/list_spec.rb
180
+ - spec/core_ext/file/which.rb
176
181
  - spec/core_ext/hash/list_spec.rb
177
182
  - spec/core_ext/hash/options_spec.rb
178
183
  - spec/core_ext/shellwords/clean_spec.rb
179
184
  - spec/core_ext/string/underline_spec.rb
180
185
  - spec/directory_finder_spec.rb
186
+ - spec/editor_spec.rb
181
187
  - spec/environment_spec.rb
182
188
  - spec/examples/models/class_based/forbidden_keyword.rb
183
189
  - spec/examples/models/class_based/ignore/ignored.rb
@@ -245,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
251
  version: '0'
246
252
  requirements: []
247
253
  rubyforge_project:
248
- rubygems_version: 2.4.1
254
+ rubygems_version: 2.2.2
249
255
  signing_key:
250
256
  specification_version: 4
251
257
  summary: Collection of useful libraries. It maybe depend on external libraries.
@@ -254,12 +260,15 @@ test_files:
254
260
  - spec/colors/html_color_spec.rb
255
261
  - spec/command/run_command_spec.rb
256
262
  - spec/command/which_spec.rb
263
+ - spec/command_finder_spec.rb
257
264
  - spec/core_ext/array/list_spec.rb
265
+ - spec/core_ext/file/which.rb
258
266
  - spec/core_ext/hash/list_spec.rb
259
267
  - spec/core_ext/hash/options_spec.rb
260
268
  - spec/core_ext/shellwords/clean_spec.rb
261
269
  - spec/core_ext/string/underline_spec.rb
262
270
  - spec/directory_finder_spec.rb
271
+ - spec/editor_spec.rb
263
272
  - spec/environment_spec.rb
264
273
  - spec/examples/models/class_based/forbidden_keyword.rb
265
274
  - spec/examples/models/class_based/ignore/ignored.rb