wright 0.1.1 → 0.1.2
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 +4 -4
- data/NEWS +5 -0
- data/README.md +3 -3
- data/Rakefile +0 -14
- data/lib/wright.rb +2 -1
- data/lib/wright/config.rb +11 -14
- data/lib/wright/dry_run.rb +7 -8
- data/lib/wright/dsl.rb +13 -11
- data/lib/wright/logger.rb +17 -16
- data/lib/wright/provider.rb +8 -8
- data/lib/wright/provider/directory.rb +5 -5
- data/lib/wright/provider/file.rb +5 -5
- data/lib/wright/provider/package.rb +9 -8
- data/lib/wright/provider/package/apt.rb +7 -9
- data/lib/wright/provider/symlink.rb +9 -9
- data/lib/wright/resource.rb +24 -24
- data/lib/wright/resource/directory.rb +15 -14
- data/lib/wright/resource/file.rb +15 -14
- data/lib/wright/resource/package.rb +14 -13
- data/lib/wright/resource/symlink.rb +11 -10
- data/lib/wright/util.rb +17 -19
- data/lib/wright/util/color.rb +14 -15
- data/lib/wright/util/file.rb +50 -55
- data/lib/wright/util/file_permissions.rb +30 -23
- data/lib/wright/util/recursive_autoloader.rb +10 -12
- data/lib/wright/util/stolen_from_activesupport.rb +42 -43
- data/lib/wright/util/user.rb +19 -22
- data/lib/wright/version.rb +2 -2
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0005b749e54ff7904188cbd497f1757c460c0b4d
|
4
|
+
data.tar.gz: b1fc596dc236a11f9a18c9de89823c91f0d20fee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9eaae5610049c8407782fd8089f789a9dbbe7208d08a46f5de4e8618b258824830c653f18c59bb0175d83b5d5661d90c276996fed278ebaa223ffce7748a706
|
7
|
+
data.tar.gz: 0975e81800682d9e93ec0d365f20ef9a4effdab230c217b2b6661eb2ffc8e1ed7d2e1ec39933f30f46795c5a42ce01343eab154bb104e3009558ceb52552abc5
|
data/NEWS
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
wright
|
2
|
+
======
|
3
|
+
|
1
4
|
[][gem]
|
2
5
|
[][travis]
|
3
6
|
[][codeclimate]
|
@@ -6,9 +9,6 @@
|
|
6
9
|
[travis]: https://travis-ci.org/sometimesfood/wright
|
7
10
|
[codeclimate]: https://codeclimate.com/github/sometimesfood/wright
|
8
11
|
|
9
|
-
wright
|
10
|
-
======
|
11
|
-
|
12
12
|
Lightweight configuration management.
|
13
13
|
|
14
14
|
Requirements
|
data/Rakefile
CHANGED
@@ -1,21 +1,7 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
2
|
require 'bundler/gem_tasks'
|
3
3
|
require 'rake/testtask'
|
4
|
-
require 'rdoc/task'
|
5
4
|
|
6
5
|
Rake::TestTask.new do |t|
|
7
6
|
t.pattern = 'spec/**/*_spec.rb'
|
8
7
|
end
|
9
|
-
|
10
|
-
RDoc::Task.new(clobber_rdoc: 'rdoc:clobber',
|
11
|
-
rerdoc: 'rdoc:force') do |t|
|
12
|
-
t.rdoc_files.include('lib/**/*.rb')
|
13
|
-
t.options << '--markup=tomdoc'
|
14
|
-
end
|
15
|
-
|
16
|
-
namespace :rdoc do
|
17
|
-
desc 'Show RDoc coverage report'
|
18
|
-
task :coverage do
|
19
|
-
exec 'rdoc --markup=tomdoc --coverage-report lib/'
|
20
|
-
end
|
21
|
-
end
|
data/lib/wright.rb
CHANGED
data/lib/wright/config.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
|
3
3
|
module Wright
|
4
|
-
#
|
4
|
+
# Configuration container, wraps a regular Ruby hash.
|
5
5
|
#
|
6
6
|
# Useful for getting and setting configuration values, such as
|
7
|
-
# logging verbosity,
|
8
|
-
#
|
9
|
-
# Examples
|
7
|
+
# logging verbosity, color output and provider configuration.
|
10
8
|
#
|
9
|
+
# @example
|
11
10
|
# Wright::Config[:foo] = { bar: :baz }
|
12
11
|
# Wright::Config[:foo][:bar]
|
13
12
|
# # => :baz
|
@@ -19,12 +18,11 @@ module Wright
|
|
19
18
|
end
|
20
19
|
private_class_method :new
|
21
20
|
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# path - The configuration item as an argument list.
|
21
|
+
# Checks if a (nested) configuration value is set.
|
25
22
|
#
|
26
|
-
#
|
23
|
+
# @param path [Array<Symbol>] the configuration key
|
27
24
|
#
|
25
|
+
# @example
|
28
26
|
# Wright::Config[:foo] = { bar: :baz }
|
29
27
|
# Wright::Config.nested_key?(:foo, :bar)
|
30
28
|
# # => true
|
@@ -32,7 +30,7 @@ module Wright
|
|
32
30
|
# Wright::Config.nested_key?(:this, :doesnt, :exist)
|
33
31
|
# # => false
|
34
32
|
#
|
35
|
-
#
|
33
|
+
# @return [Bool] true if the configuration value is set and false
|
36
34
|
# otherwise.
|
37
35
|
def self.nested_key?(*path)
|
38
36
|
last_key = path.pop
|
@@ -43,12 +41,11 @@ module Wright
|
|
43
41
|
last_hash.respond_to?(:key?) && last_hash.key?(last_key)
|
44
42
|
end
|
45
43
|
|
46
|
-
#
|
47
|
-
#
|
48
|
-
# path - The configuration item as an argument list.
|
44
|
+
# Retrieves a (nested) configuration value.
|
49
45
|
#
|
50
|
-
#
|
46
|
+
# @param path [Array<Symbol>] the configuration key
|
51
47
|
#
|
48
|
+
# @example
|
52
49
|
# Wright::Config[:foo] = { bar: :baz }
|
53
50
|
# Wright::Config.nested_value(:foo, :bar)
|
54
51
|
# # => :baz
|
@@ -56,7 +53,7 @@ module Wright
|
|
56
53
|
# Wright::Config.nested_value(:this, :doesnt, :exist)
|
57
54
|
# # => nil
|
58
55
|
#
|
59
|
-
#
|
56
|
+
# @return the configuration value or nil if the value is not set
|
60
57
|
def self.nested_value(*path)
|
61
58
|
nested_key?(*path) ? path.reduce(@config_hash) { |a, e| a[e] } : nil
|
62
59
|
end
|
data/lib/wright/dry_run.rb
CHANGED
@@ -1,28 +1,27 @@
|
|
1
1
|
module Wright # rubocop:disable Documentation
|
2
2
|
@dry_run = false
|
3
3
|
|
4
|
-
#
|
5
|
-
#
|
6
|
-
# Examples
|
4
|
+
# Checks if dry-run mode is currently active.
|
7
5
|
#
|
6
|
+
# @example
|
8
7
|
# puts 'Just a dry-run...' if Wright.dry_run?
|
9
8
|
#
|
10
|
-
#
|
9
|
+
# @return [Bool] true if dry-run mode is currently active and false
|
10
|
+
# otherwise
|
11
11
|
def self.dry_run?
|
12
12
|
@dry_run
|
13
13
|
end
|
14
14
|
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# Examples
|
15
|
+
# Runs a block in dry-run mode.
|
18
16
|
#
|
17
|
+
# @example
|
19
18
|
# Wright.dry_run do
|
20
19
|
# symlink '/tmp/fstab' do |s|
|
21
20
|
# s.to = '/etc/fstab'
|
22
21
|
# end
|
23
22
|
# end
|
24
23
|
#
|
25
|
-
#
|
24
|
+
# @return the block's return value
|
26
25
|
def self.dry_run
|
27
26
|
saved_dry_run = @dry_run
|
28
27
|
@dry_run = true
|
data/lib/wright/dsl.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'wright/util'
|
2
2
|
|
3
3
|
module Wright
|
4
|
-
#
|
4
|
+
# Includable Wright script DSL.
|
5
5
|
#
|
6
6
|
# Contains resource methods for all registered resources.
|
7
7
|
#
|
8
|
-
#
|
9
|
-
#
|
8
|
+
# @example
|
10
9
|
# # define a new resource at runtime
|
11
10
|
# class KitchenSink < Wright::Resource; end
|
12
11
|
#
|
@@ -28,16 +27,17 @@ module Wright
|
|
28
27
|
# a_sink_to_remember.class
|
29
28
|
# # => KitchenSink
|
30
29
|
module DSL
|
31
|
-
#
|
30
|
+
# Registers a class as a resource.
|
32
31
|
#
|
33
32
|
# Creates a resource method in the DSL module. Uses the
|
34
33
|
# snake-cased class name as method name.
|
35
34
|
#
|
36
|
-
# resource_class
|
37
|
-
#
|
38
|
-
#
|
35
|
+
# Typically resource_class is a subclass of {Resource}. It is
|
36
|
+
# initialized with the resource's name as an argument.
|
37
|
+
#
|
38
|
+
# @param resource_class the resource class
|
39
39
|
#
|
40
|
-
#
|
40
|
+
# @return [void]
|
41
41
|
def self.register_resource(resource_class)
|
42
42
|
method_name = Util.class_to_resource_name(resource_class)
|
43
43
|
this_module = self
|
@@ -46,13 +46,15 @@ module Wright
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
#
|
50
|
-
# default action.
|
49
|
+
# @api private
|
50
|
+
# Instantiates a resource and performs its default action.
|
51
51
|
#
|
52
52
|
# Implicitly invoking a block from within another block does not
|
53
53
|
# work: http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html
|
54
54
|
#
|
55
|
-
#
|
55
|
+
# @yield [resource] the resource
|
56
|
+
#
|
57
|
+
# @return [void]
|
56
58
|
def self.yield_resource(resource_class, name)
|
57
59
|
r = resource_class.new(name)
|
58
60
|
yield(r) if block_given?
|
data/lib/wright/logger.rb
CHANGED
@@ -4,18 +4,20 @@ require 'wright/config'
|
|
4
4
|
require 'wright/util/color'
|
5
5
|
|
6
6
|
module Wright # rubocop:disable Documentation
|
7
|
-
#
|
7
|
+
# Default logger for Wright.
|
8
8
|
class Logger < ::Logger
|
9
|
-
#
|
9
|
+
# @api private
|
10
|
+
# Default formatter for Wright log messages.
|
10
11
|
class Formatter < ::Logger::Formatter
|
11
|
-
#
|
12
|
+
# This method is called by {Wright::Logger} to format log
|
13
|
+
# messages.
|
12
14
|
#
|
13
|
-
# severity
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# message
|
15
|
+
# @param severity [String] the log entry's severity
|
16
|
+
# @param _time [Time] the log entry's time stamp (ignored)
|
17
|
+
# @param _progname [String] the log entry's program name (ignored)
|
18
|
+
# @param message [String] the log message
|
17
19
|
#
|
18
|
-
#
|
20
|
+
# @return [String] the formatted log entry
|
19
21
|
def call(severity, _time, _progname, message)
|
20
22
|
log_entry = "#{severity}: #{message}\n"
|
21
23
|
if Wright::Config[:log][:colorize]
|
@@ -27,13 +29,12 @@ module Wright # rubocop:disable Documentation
|
|
27
29
|
|
28
30
|
private
|
29
31
|
|
30
|
-
#
|
31
|
-
# severity.
|
32
|
+
# ANSI-Colorizes a log message according to its severity.
|
32
33
|
#
|
33
|
-
# string
|
34
|
-
# severity
|
34
|
+
# @param string [String] the log message to be colorized
|
35
|
+
# @param severity [String] the severity of the log message
|
35
36
|
#
|
36
|
-
#
|
37
|
+
# @return [String] the colorized log message
|
37
38
|
def colorize(string, severity)
|
38
39
|
case severity
|
39
40
|
when 'ERROR', 'FATAL'
|
@@ -48,12 +49,12 @@ module Wright # rubocop:disable Documentation
|
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
#
|
52
|
+
# Initializes a Logger.
|
52
53
|
#
|
53
54
|
# Enables log colorization if the log device is a TTY and
|
54
55
|
# colorization was not disabled before initialization.
|
55
56
|
#
|
56
|
-
# logdev
|
57
|
+
# @param logdev [IO] the log device used by the Logger.
|
57
58
|
def initialize(logdev = $stdout)
|
58
59
|
super
|
59
60
|
Wright::Config[:log] ||= {}
|
@@ -64,7 +65,7 @@ module Wright # rubocop:disable Documentation
|
|
64
65
|
end
|
65
66
|
|
66
67
|
class << self
|
67
|
-
#
|
68
|
+
# @return [Logger] the logger used by Wright
|
68
69
|
attr_accessor :log
|
69
70
|
end
|
70
71
|
@log = Wright::Logger.new
|
data/lib/wright/provider.rb
CHANGED
@@ -2,26 +2,26 @@ require 'wright/config'
|
|
2
2
|
require 'wright/util/recursive_autoloader'
|
3
3
|
|
4
4
|
module Wright
|
5
|
-
#
|
5
|
+
# Provider class.
|
6
6
|
class Provider
|
7
|
-
#
|
7
|
+
# Wright standard provider directory
|
8
8
|
PROVIDER_DIR = File.expand_path('provider', File.dirname(__FILE__))
|
9
9
|
|
10
10
|
Wright::Util::RecursiveAutoloader.add_autoloads(PROVIDER_DIR, name)
|
11
11
|
|
12
|
-
#
|
12
|
+
# Initializes a Provider.
|
13
13
|
#
|
14
|
-
# resource
|
15
|
-
# Wright::Resource.
|
14
|
+
# @param resource [Resource] the resource used by the provider
|
16
15
|
def initialize(resource)
|
17
16
|
@resource = resource
|
18
17
|
@updated = false
|
19
18
|
end
|
20
19
|
|
21
|
-
#
|
22
|
-
#
|
20
|
+
# Checks if the provider was updated since the last call to
|
21
|
+
# {#updated?}
|
23
22
|
#
|
24
|
-
#
|
23
|
+
# @return [Bool] true if the provider was updated and false
|
24
|
+
# otherwise
|
25
25
|
def updated?
|
26
26
|
updated = @updated
|
27
27
|
@updated = false
|
@@ -6,11 +6,11 @@ require 'wright/util/file_permissions'
|
|
6
6
|
|
7
7
|
module Wright
|
8
8
|
class Provider
|
9
|
-
#
|
9
|
+
# Directory provider. Used as a provider for {Resource::Directory}.
|
10
10
|
class Directory < Wright::Provider
|
11
|
-
#
|
11
|
+
# Creates or updates the directory.
|
12
12
|
#
|
13
|
-
#
|
13
|
+
# @return [void]
|
14
14
|
def create
|
15
15
|
if ::File.directory?(dirname) && permissions.uptodate?
|
16
16
|
Wright.log.debug "directory already created: '#{@resource.name}'"
|
@@ -22,9 +22,9 @@ module Wright
|
|
22
22
|
@updated = true
|
23
23
|
end
|
24
24
|
|
25
|
-
#
|
25
|
+
# Removes the directory.
|
26
26
|
#
|
27
|
-
#
|
27
|
+
# @return [void]
|
28
28
|
def remove
|
29
29
|
if ::File.exist?(dirname) && !::File.directory?(dirname)
|
30
30
|
fail "'#{dirname}' exists but is not a directory"
|
data/lib/wright/provider/file.rb
CHANGED
@@ -8,11 +8,11 @@ require 'tmpdir'
|
|
8
8
|
|
9
9
|
module Wright
|
10
10
|
class Provider
|
11
|
-
#
|
11
|
+
# File provider. Used as a provider for {Resource::File}.
|
12
12
|
class File < Wright::Provider
|
13
|
-
#
|
13
|
+
# Creates or updates the file.
|
14
14
|
#
|
15
|
-
#
|
15
|
+
# @return [void]
|
16
16
|
def create
|
17
17
|
fail Errno::EISDIR, filename if ::File.directory?(filename)
|
18
18
|
|
@@ -25,9 +25,9 @@ module Wright
|
|
25
25
|
@updated = true
|
26
26
|
end
|
27
27
|
|
28
|
-
#
|
28
|
+
# Removes the file.
|
29
29
|
#
|
30
|
-
#
|
30
|
+
# @return [void]
|
31
31
|
def remove
|
32
32
|
fail Errno::EISDIR, filename if ::File.directory?(filename)
|
33
33
|
|
@@ -2,19 +2,20 @@ require 'wright/provider'
|
|
2
2
|
|
3
3
|
module Wright
|
4
4
|
class Provider
|
5
|
-
#
|
6
|
-
#
|
5
|
+
# Package provider. Used as a base class for Resource::Package
|
6
|
+
# providers.
|
7
7
|
class Package < Wright::Provider
|
8
8
|
private
|
9
9
|
|
10
|
-
#
|
11
|
-
# action.
|
10
|
+
# @api public
|
11
|
+
# Checks if the package is up-to-date for a given action.
|
12
12
|
#
|
13
|
-
# action
|
14
|
-
#
|
13
|
+
# @param action [Symbol] the action. Currently supports
|
14
|
+
# +:install+ and +:remove+.
|
15
15
|
#
|
16
|
-
#
|
17
|
-
#
|
16
|
+
# @return [Bool] +true+ if the package is up-to-date and +false+
|
17
|
+
# otherwise
|
18
|
+
# @raise [ArgumentError] if the action is invalid
|
18
19
|
def uptodate?(action)
|
19
20
|
case action
|
20
21
|
when :install
|
@@ -7,12 +7,10 @@ require 'wright/provider/package'
|
|
7
7
|
module Wright
|
8
8
|
class Provider
|
9
9
|
class Package
|
10
|
-
#
|
11
|
-
# Resource::Package on Debian-based systems.
|
10
|
+
# Apt package provider. Used as a Provider for
|
11
|
+
# {Resource::Package} on Debian-based systems.
|
12
12
|
class Apt < Wright::Provider::Package
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# Returns an array of installed package version Strings.
|
13
|
+
# @return [Array<String>] the installed package versions
|
16
14
|
def installed_versions
|
17
15
|
cmd = "dpkg-query -s #{@resource.name}"
|
18
16
|
cmd_stdout, _cmd_stderr, cmd_status = Open3.capture3(env, cmd)
|
@@ -26,9 +24,9 @@ module Wright
|
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
29
|
-
#
|
27
|
+
# Installs the package.
|
30
28
|
#
|
31
|
-
#
|
29
|
+
# @return [void]
|
32
30
|
def install
|
33
31
|
if uptodate?(:install)
|
34
32
|
Wright.log.debug "package already installed: '#{@resource.name}'"
|
@@ -39,9 +37,9 @@ module Wright
|
|
39
37
|
@updated = true
|
40
38
|
end
|
41
39
|
|
42
|
-
#
|
40
|
+
# Removes the package.
|
43
41
|
#
|
44
|
-
#
|
42
|
+
# @return [void]
|
45
43
|
def remove
|
46
44
|
if uptodate?(:remove)
|
47
45
|
Wright.log.debug "package already removed: '#{@resource.name}'"
|