garcun 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/garcon/chef/chef_helpers.rb +9 -12
- data/lib/garcon/chef/coerce/coercer.rb +3 -0
- data/lib/garcon/chef/node.rb +7 -5
- data/lib/garcon/chef/provider/download.rb +2 -30
- data/lib/garcon/chef/resource/base_dsl.rb +53 -0
- data/lib/garcon/chef/secret_bag.rb +2 -1
- data/lib/garcon/chef_inclusions.rb +1 -9
- data/lib/garcon/core_ext/array.rb +1 -1
- data/lib/garcon/core_ext/binding.rb +0 -1
- data/lib/garcon/core_ext/boolean.rb +2 -0
- data/lib/garcon/core_ext/hash.rb +1 -2
- data/lib/garcon/core_ext/kernel.rb +0 -2
- data/lib/garcon/core_ext/module.rb +0 -1
- data/lib/garcon/core_ext/object.rb +0 -3
- data/lib/garcon/core_ext/string.rb +9 -15
- data/lib/garcon/core_ext/struct.rb +0 -1
- data/lib/garcon/core_ext/symbol.rb +0 -1
- data/lib/garcon/core_ext/time.rb +0 -1
- data/lib/garcon/core_ext.rb +0 -4
- data/lib/garcon/exceptions.rb +0 -35
- data/lib/garcon/task/executor.rb +0 -1
- data/lib/garcon/task/ivar.rb +0 -2
- data/lib/garcon/utility/file_helper.rb +88 -1
- data/lib/garcon/utility/retry.rb +0 -3
- data/lib/garcon/utility/timeout.rb +0 -3
- data/lib/garcon/utils.rb +0 -1
- data/lib/garcon/version.rb +1 -1
- data/lib/garcon.rb +1 -4
- data/lib/garcun.rb +1 -3
- metadata +2 -11
- data/lib/garcon/chef/handler/devreporter.rb +0 -127
- data/lib/garcon/chef/resource/resource_name.rb +0 -109
- data/lib/garcon/core_ext/file.rb +0 -127
- data/lib/garcon/core_ext/filetest.rb +0 -62
- data/lib/garcon/core_ext/lazy.rb +0 -222
- data/lib/garcon/core_ext/process.rb +0 -41
- data/lib/garcon/utility/ansi.rb +0 -199
- data/lib/garcon/utility/equalizer.rb +0 -146
- data/lib/garcon/utility/msg_from_god.rb +0 -62
data/lib/garcon.rb
CHANGED
@@ -31,7 +31,6 @@ require 'chef/provider'
|
|
31
31
|
|
32
32
|
require_relative 'garcon/version'
|
33
33
|
require_relative 'garcon/configuration'
|
34
|
-
require_relative 'garcon/exceptions'
|
35
34
|
require_relative 'garcon/inflections'
|
36
35
|
require_relative 'garcon/secret'
|
37
36
|
require_relative 'garcon/stash/store'
|
@@ -39,8 +38,6 @@ require_relative 'garcon/core_ext'
|
|
39
38
|
require_relative 'garcon/task'
|
40
39
|
require_relative 'garcon/utils'
|
41
40
|
|
42
|
-
# Pirla o Sfigato Magnà Capo Fregna
|
43
|
-
|
44
41
|
module Garcon
|
45
42
|
# Extends base class or a module with garcon methods, called when module is
|
46
43
|
# included, extends the object with class and instance methods.
|
@@ -54,7 +51,7 @@ module Garcon
|
|
54
51
|
def self.included(object)
|
55
52
|
super
|
56
53
|
if Class === object
|
57
|
-
object.send(:include, ClassInclusions)
|
54
|
+
object.send(:include, ClassInclusions)
|
58
55
|
else
|
59
56
|
object.extend(ModuleExtensions)
|
60
57
|
end
|
data/lib/garcun.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: garcun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Harding
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|
@@ -535,7 +535,6 @@ files:
|
|
535
535
|
- lib/garcon/chef/coerce/coercions/integer_definitions.rb
|
536
536
|
- lib/garcon/chef/coerce/coercions/string_definitions.rb
|
537
537
|
- lib/garcon/chef/coerce/coercions/time_definitions.rb
|
538
|
-
- lib/garcon/chef/handler/devreporter.rb
|
539
538
|
- lib/garcon/chef/log.rb
|
540
539
|
- lib/garcon/chef/node.rb
|
541
540
|
- lib/garcon/chef/provider/civilize.rb
|
@@ -550,7 +549,6 @@ files:
|
|
550
549
|
- lib/garcon/chef/resource/base_dsl.rb
|
551
550
|
- lib/garcon/chef/resource/blender.rb
|
552
551
|
- lib/garcon/chef/resource/lazy_eval.rb
|
553
|
-
- lib/garcon/chef/resource/resource_name.rb
|
554
552
|
- lib/garcon/chef/secret_bag.rb
|
555
553
|
- lib/garcon/chef/validations.rb
|
556
554
|
- lib/garcon/chef_inclusions.rb
|
@@ -561,18 +559,14 @@ files:
|
|
561
559
|
- lib/garcon/core_ext/boolean.rb
|
562
560
|
- lib/garcon/core_ext/duration.rb
|
563
561
|
- lib/garcon/core_ext/enumerable.rb
|
564
|
-
- lib/garcon/core_ext/file.rb
|
565
|
-
- lib/garcon/core_ext/filetest.rb
|
566
562
|
- lib/garcon/core_ext/hash.rb
|
567
563
|
- lib/garcon/core_ext/kernel.rb
|
568
|
-
- lib/garcon/core_ext/lazy.rb
|
569
564
|
- lib/garcon/core_ext/method_access.rb
|
570
565
|
- lib/garcon/core_ext/module.rb
|
571
566
|
- lib/garcon/core_ext/nil.rb
|
572
567
|
- lib/garcon/core_ext/numeric.rb
|
573
568
|
- lib/garcon/core_ext/object.rb
|
574
569
|
- lib/garcon/core_ext/pathname.rb
|
575
|
-
- lib/garcon/core_ext/process.rb
|
576
570
|
- lib/garcon/core_ext/random.rb
|
577
571
|
- lib/garcon/core_ext/string.rb
|
578
572
|
- lib/garcon/core_ext/struct.rb
|
@@ -621,10 +615,8 @@ files:
|
|
621
615
|
- lib/garcon/task/timer_set.rb
|
622
616
|
- lib/garcon/task/timer_task.rb
|
623
617
|
- lib/garcon/task/waitable_list.rb
|
624
|
-
- lib/garcon/utility/ansi.rb
|
625
618
|
- lib/garcon/utility/at_random.rb
|
626
619
|
- lib/garcon/utility/crypto.rb
|
627
|
-
- lib/garcon/utility/equalizer.rb
|
628
620
|
- lib/garcon/utility/faker/extensions/array.rb
|
629
621
|
- lib/garcon/utility/faker/extensions/symbol.rb
|
630
622
|
- lib/garcon/utility/faker/faker.rb
|
@@ -638,7 +630,6 @@ files:
|
|
638
630
|
- lib/garcon/utility/interpolation.rb
|
639
631
|
- lib/garcon/utility/memstash.rb
|
640
632
|
- lib/garcon/utility/misc.rb
|
641
|
-
- lib/garcon/utility/msg_from_god.rb
|
642
633
|
- lib/garcon/utility/retry.rb
|
643
634
|
- lib/garcon/utility/timeout.rb
|
644
635
|
- lib/garcon/utility/uber/builder.rb
|
@@ -1,127 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
#
|
3
|
-
# Author: Stefano Harding <riddopic@gmail.com>
|
4
|
-
# License: Apache License, Version 2.0
|
5
|
-
# Copyright: (C) 2014-2015 Stefano Harding
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
|
20
|
-
require 'chef'
|
21
|
-
require 'chef/log'
|
22
|
-
require 'chef/handler'
|
23
|
-
require 'garcon'
|
24
|
-
|
25
|
-
class DevReporter < Chef::Handler
|
26
|
-
attr_reader :resources, :immediate, :delayed, :always
|
27
|
-
|
28
|
-
def initialize(opts = {})
|
29
|
-
end
|
30
|
-
|
31
|
-
def full_name(resource)
|
32
|
-
"#{resource.resource_name}[#{resource.name}]"
|
33
|
-
end
|
34
|
-
|
35
|
-
def humanize(seconds)
|
36
|
-
[[60, :seconds],
|
37
|
-
[60, :minutes],
|
38
|
-
[24, :hours],
|
39
|
-
[1000, :days] ].map do |count, name|
|
40
|
-
if seconds > 0
|
41
|
-
seconds, n = seconds.divmod(count)
|
42
|
-
"#{n.to_i} #{name}"
|
43
|
-
end
|
44
|
-
end.compact.reverse.join(' ')
|
45
|
-
end
|
46
|
-
|
47
|
-
def banner
|
48
|
-
puts <<-EOF
|
49
|
-
|
50
|
-
|
51
|
-
.: ;:. .:;S;:. .:;.;:. .:;S;:. .:;S;:.
|
52
|
-
S ' S S S S S S S /
|
53
|
-
`:;S;:' `:;S;:' `:;S;:' `:;S;:' `:;S;:'
|
54
|
-
.g8"""bgd
|
55
|
-
.dP' `M
|
56
|
-
dM' ` ,6"Yb. `7Mb,od8 ,p6"bo ,pW"Wq.`7MMpMMMb.
|
57
|
-
MM 8) MM MM' "'6M' OO 6W' `Wb MM MM
|
58
|
-
MM. `7MMF',pm9MM MM 8M 8M M8 MM MM
|
59
|
-
`Mb. MM 8M MM MM YM. , YA. ,A9 MM MM
|
60
|
-
`"bmmmdPY `Moo9^Yo..JMML. YMbmd' `Ybmd9'.JMML JMML.
|
61
|
-
bog
|
62
|
-
od V #{Garcon::VERSION}
|
63
|
-
|
64
|
-
EOF
|
65
|
-
end
|
66
|
-
|
67
|
-
def report
|
68
|
-
if run_status.success?
|
69
|
-
cookbooks = Hash.new(0)
|
70
|
-
recipes = Hash.new(0)
|
71
|
-
resources = Hash.new(0)
|
72
|
-
run_time = humanize(run_status.elapsed_time)
|
73
|
-
updates = run_status.updated_resources.length
|
74
|
-
total = run_status.all_resources.length
|
75
|
-
|
76
|
-
all_resources.each do |r|
|
77
|
-
cookbooks[r.cookbook_name] += r.elapsed_time
|
78
|
-
recipes["#{r.cookbook_name}::#{r.recipe_name}"] += r.elapsed_time
|
79
|
-
resources["#{r.resource_name}[#{r.name}]"] = r.elapsed_time
|
80
|
-
end
|
81
|
-
|
82
|
-
@max_time = all_resources.max_by { |r| r.elapsed_time }.elapsed_time
|
83
|
-
@max = all_resources.max_by { |r| full_name(r).length }
|
84
|
-
|
85
|
-
# Start droping puts because mash grinder faceplanted Chef::Log.info
|
86
|
-
# logging changes random so excelent thanks Chef!
|
87
|
-
#
|
88
|
-
puts ''
|
89
|
-
puts '*|*|*|*|*|*|*|*|* <`)))>< '
|
90
|
-
banner
|
91
|
-
puts 'Elapsed Time Cookbook Version'.yellow
|
92
|
-
puts '------------ ------------------- ----------------------'.green
|
93
|
-
cookbooks.sort_by { |k, v| -v }.each do |cookbook, run_time|
|
94
|
-
ver = run_context.cookbook_collection[cookbook.to_sym].version
|
95
|
-
puts '%19f %-20s %-7s' % [run_time, cookbook, ver]
|
96
|
-
end
|
97
|
-
puts ''
|
98
|
-
puts 'Elapsed Time Recipe'.orange
|
99
|
-
puts '------------ -------------------------------------------'.green
|
100
|
-
recipes.sort_by { |k, v| -v }.each do |recipe, run_time|
|
101
|
-
puts '%19f %s' % [run_time, recipe]
|
102
|
-
end
|
103
|
-
puts ''
|
104
|
-
puts 'Elapsed Time Resource'.orange
|
105
|
-
puts '------------ -------------------------------------------'.green
|
106
|
-
resources.sort_by { |k, v| -v }.each do |resource, run_time|
|
107
|
-
puts '%19f %s' % [run_time, resource]
|
108
|
-
end
|
109
|
-
puts '+-----------------------------------------------------------------'\
|
110
|
-
'-------------+'.purple
|
111
|
-
puts ''
|
112
|
-
puts "Chef Run Completed in #{run_time} on #{node.name}. Updated " \
|
113
|
-
"#{updates} of #{total} resources."
|
114
|
-
|
115
|
-
cookbooks = run_context.cookbook_collection
|
116
|
-
puts
|
117
|
-
puts "Slowest Resource: #{full_name(@max)} (%.6fs)"%[@max_time]
|
118
|
-
puts ''
|
119
|
-
puts Faker::Hacker.say_something_smart
|
120
|
-
puts ''
|
121
|
-
elsif run_status.failed?
|
122
|
-
banner
|
123
|
-
puts "Chef FAILED in #{run_time} on #{node.name} with exception:".orange
|
124
|
-
puts run_status.formatted_exception
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
#
|
3
|
-
# Author: Stefano Harding <riddopic@gmail.com>
|
4
|
-
# License: Apache License, Version 2.0
|
5
|
-
# Copyright: (C) 2014-2015 Stefano Harding
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
|
20
|
-
module Garcon
|
21
|
-
module Resource
|
22
|
-
# Helper module to automatically set @resource_name.
|
23
|
-
#
|
24
|
-
# @example
|
25
|
-
# class MyResource < Chef::Resource
|
26
|
-
# include Garcon
|
27
|
-
#
|
28
|
-
# provides :my_resource
|
29
|
-
# end
|
30
|
-
#
|
31
|
-
module ResourceName
|
32
|
-
# Constructor for Chef::Resource::MyResource.
|
33
|
-
#
|
34
|
-
def initialize(*args)
|
35
|
-
super
|
36
|
-
if self.class.resource_name(false)
|
37
|
-
@resource_name = self.class.resource_name
|
38
|
-
else
|
39
|
-
@resource_name ||= self.class.resource_name
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
module ClassMethods
|
44
|
-
# Maps a resource/provider (and optionally a platform and version) to a
|
45
|
-
# Chef resource/provider. This allows finer grained per platform
|
46
|
-
# resource attributes and the end of overloaded resource definitions.
|
47
|
-
#
|
48
|
-
# @note
|
49
|
-
# The provides method must be defined in both the custom resource and
|
50
|
-
# custom provider files and both files must have identical provides
|
51
|
-
# statement(s).
|
52
|
-
#
|
53
|
-
# @param [Symbol] name
|
54
|
-
# Name of a Chef resource/provider to map to.
|
55
|
-
#
|
56
|
-
# @return [undefined]
|
57
|
-
#
|
58
|
-
def provides(name)
|
59
|
-
if self.name && respond_to?(:constantize)
|
60
|
-
old_constantize = instance_method(:constantize)
|
61
|
-
define_singleton_method(:constantize) do |name|
|
62
|
-
name == self.name ? self : old_constantize.bind(self).call(name)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
@provides_name = name
|
66
|
-
super if defined?(super)
|
67
|
-
end
|
68
|
-
|
69
|
-
# Return the Snake case name of the current resource class. If not set
|
70
|
-
# explicitly it will be introspected based on the class name.
|
71
|
-
#
|
72
|
-
# @param [Boolean] auto
|
73
|
-
# Try to auto-detect based on class name.
|
74
|
-
#
|
75
|
-
# @return [Symbol]
|
76
|
-
#
|
77
|
-
def resource_name(auto = true)
|
78
|
-
return @provides_name if @provides_name
|
79
|
-
@provides_name || if name && name.start_with?('Chef::Resource')
|
80
|
-
Garcon::Inflections.snakeify(name, 'Chef::Resource').to_sym
|
81
|
-
elsif name
|
82
|
-
Garcon::Inflections.snakeify(name.split('::').last).to_sym
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# Used by Resource#to_text to find the human name for the resource.
|
87
|
-
#
|
88
|
-
def dsl_name
|
89
|
-
resource_name.to_s
|
90
|
-
end
|
91
|
-
|
92
|
-
# Hook called when module is included, extends a descendant with class
|
93
|
-
# and instance methods.
|
94
|
-
#
|
95
|
-
# @param [Module] descendant
|
96
|
-
# the module or class including Garcon::Resource::ResourceName
|
97
|
-
#
|
98
|
-
# @return [self]
|
99
|
-
#
|
100
|
-
def included(descendant)
|
101
|
-
super
|
102
|
-
descendant.extend ClassMethods
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
extend ClassMethods
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
data/lib/garcon/core_ext/file.rb
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
#
|
3
|
-
# Author: Stefano Harding <riddopic@gmail.com>
|
4
|
-
# License: Apache License, Version 2.0
|
5
|
-
# Copyright: (C) 2014-2015 Stefano Harding
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
|
20
|
-
require 'thread' unless defined?(Thread)
|
21
|
-
require 'tempfile' unless defined?(Tempfile)
|
22
|
-
require 'fileutils' unless defined?(FileUtils)
|
23
|
-
|
24
|
-
class File
|
25
|
-
|
26
|
-
def self.atomic_id
|
27
|
-
@atomic_id ||= 0
|
28
|
-
@atomic_id += 1
|
29
|
-
end
|
30
|
-
|
31
|
-
# Same as `File.open`, but acts on a temporary copy of named
|
32
|
-
# file, copying the file back to the original on completion.
|
33
|
-
#
|
34
|
-
# @uncommon
|
35
|
-
# require 'facets/fileutils/atomic_open'
|
36
|
-
#
|
37
|
-
def self.atomic_open(file_name, mode="r", temp_dir=nil, &block)
|
38
|
-
temp_dir = temp_dir || Dir.tmpdir
|
39
|
-
temp_file = Tempfile.new("#{aomtic_id}-" + basename(file_name), temp_dir)
|
40
|
-
|
41
|
-
if File.exist?(file_name)
|
42
|
-
FileUtils.cp(file_name, temp_file)
|
43
|
-
end
|
44
|
-
|
45
|
-
open(temp_file, mode, &block)
|
46
|
-
|
47
|
-
FileUtils.cp(temp_file, file_name)
|
48
|
-
end
|
49
|
-
|
50
|
-
# Write to a file atomically. Useful for situations where you don't
|
51
|
-
# want other processes or threads to see half-written files.
|
52
|
-
#
|
53
|
-
# File.atomic_write("important.txt") do |file|
|
54
|
-
# file.write("hello")
|
55
|
-
# end
|
56
|
-
#
|
57
|
-
# If your temporary directory is not on the same filesystem as the file you're
|
58
|
-
# trying to write, you can provide a different temporary directory.
|
59
|
-
#
|
60
|
-
# File.atomic_write("important.txt", "tmp") do |file|
|
61
|
-
# file.write("hello")
|
62
|
-
# end
|
63
|
-
#
|
64
|
-
# NOTE: This method is not a common core extension and is not
|
65
|
-
# loaded automatically when using <code>require 'facets'</code>.
|
66
|
-
#
|
67
|
-
# CREDIT: David Heinemeier Hansson
|
68
|
-
#
|
69
|
-
# @uncommon
|
70
|
-
# require 'facets/fileutils/atomic_write'
|
71
|
-
#
|
72
|
-
def self.atomic_write(file_name, temp_dir=nil)
|
73
|
-
temp_dir = temp_dir || Dir.tmpdir
|
74
|
-
temp_file = Tempfile.new(basename(file_name), temp_dir)
|
75
|
-
|
76
|
-
yield temp_file
|
77
|
-
temp_file.close
|
78
|
-
|
79
|
-
begin
|
80
|
-
## Get original file permissions
|
81
|
-
old_stat = stat(file_name)
|
82
|
-
rescue Errno::ENOENT
|
83
|
-
## No old permissions, write a temp file to determine the defaults
|
84
|
-
check_name = join(dirname(file_name), ".permissions_check.#{Thread.current.object_id}.#{Process.pid}.#{rand(1000000)}")
|
85
|
-
open(check_name, "w") { }
|
86
|
-
old_stat = stat(check_name)
|
87
|
-
unlink(check_name)
|
88
|
-
end
|
89
|
-
|
90
|
-
## Overwrite original file with temp file
|
91
|
-
FileUtils.mv(temp_file.path, file_name)
|
92
|
-
|
93
|
-
## Set correct permissions on new file
|
94
|
-
chown(old_stat.uid, old_stat.gid, file_name)
|
95
|
-
chmod(old_stat.mode, file_name)
|
96
|
-
end
|
97
|
-
|
98
|
-
# Reads in a file, removes blank lines and removes lines starting
|
99
|
-
# with '#' and then returns an array of all the remaining lines.
|
100
|
-
#
|
101
|
-
# Thr remark indicator can be overridden via the +:omit:+ option, which
|
102
|
-
# can be a regualar expression or a string that is match against the
|
103
|
-
# start of a line.
|
104
|
-
#
|
105
|
-
# CREDIT: Trans
|
106
|
-
|
107
|
-
def self.read_list(filepath, options={})
|
108
|
-
chomp = options[:chomp]
|
109
|
-
omit = case options[:omit]
|
110
|
-
when Regexp
|
111
|
-
omit
|
112
|
-
when nil
|
113
|
-
/^\s*\#/
|
114
|
-
else
|
115
|
-
/^\s*#{Regexp.escape(omit)}/
|
116
|
-
end
|
117
|
-
|
118
|
-
list = []
|
119
|
-
readlines(filepath).each do |line|
|
120
|
-
line = line.strip.chomp(chomp)
|
121
|
-
next if line.empty?
|
122
|
-
next if omit === line
|
123
|
-
list << line
|
124
|
-
end
|
125
|
-
list
|
126
|
-
end
|
127
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
#
|
3
|
-
# Author: Stefano Harding <riddopic@gmail.com>
|
4
|
-
# License: Apache License, Version 2.0
|
5
|
-
# Copyright: (C) 2014-2015 Stefano Harding
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
|
20
|
-
module FileTest
|
21
|
-
|
22
|
-
SEPARATOR_PATTERN = (
|
23
|
-
if File::ALT_SEPARATOR
|
24
|
-
/[#{Regexp.quote File::ALT_SEPARATOR}#{Regexp.quote File::SEPARATOR}]/
|
25
|
-
else
|
26
|
-
/#{Regexp.quote File::SEPARATOR}/
|
27
|
-
end
|
28
|
-
).freeze
|
29
|
-
|
30
|
-
module_function
|
31
|
-
|
32
|
-
# Predicate method for testing whether a path is absolute.
|
33
|
-
# It returns +true+ if the pathname begins with a slash.
|
34
|
-
def absolute?(path)
|
35
|
-
!relative?(path)
|
36
|
-
end
|
37
|
-
|
38
|
-
# The opposite of #absolute?
|
39
|
-
def relative?(path)
|
40
|
-
while r = chop_basename(path.to_s)
|
41
|
-
path, _ = r
|
42
|
-
end
|
43
|
-
path == ''
|
44
|
-
end
|
45
|
-
|
46
|
-
# List File.split, but preserves the file separators.
|
47
|
-
#
|
48
|
-
# FileTest.chop_basename('/usr/lib') #=> ['/usr/', 'lib']
|
49
|
-
# FileTest.chop_basename('/') #=> nil
|
50
|
-
#
|
51
|
-
# Returns Array of `[pre-basename, basename]` or `nil`.
|
52
|
-
#
|
53
|
-
# This method is here simply to support the #relative? and #absolute? methods.
|
54
|
-
def chop_basename(path)
|
55
|
-
base = File.basename(path)
|
56
|
-
if /\A#{SEPARATOR_PATTERN}?\z/ =~ base
|
57
|
-
return nil
|
58
|
-
else
|
59
|
-
return path[0, path.rindex(base)], base
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|