wright 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -25,20 +25,19 @@
|
|
25
25
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
26
26
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27
27
|
|
28
|
-
module Wright
|
28
|
+
module Wright
|
29
29
|
module Util
|
30
|
-
#
|
31
|
-
#
|
30
|
+
# @api private
|
31
|
+
# Various methods copied verbatim from ActiveSupport in
|
32
|
+
# order to keep dependencies to a minimum.
|
32
33
|
module ActiveSupport
|
33
|
-
#
|
34
|
-
# lowercase form.
|
34
|
+
# Converts a CamelCased string to underscored, lowercase form.
|
35
35
|
#
|
36
36
|
# Changes '::' to '/' to convert namespaces to paths.
|
37
37
|
#
|
38
|
-
# camel_cased_word
|
39
|
-
#
|
40
|
-
# Examples
|
38
|
+
# @param camel_cased_word [String] the string to be converted
|
41
39
|
#
|
40
|
+
# @example
|
42
41
|
# underscore("ActiveModel")
|
43
42
|
# # => "active_model"
|
44
43
|
#
|
@@ -46,12 +45,13 @@ module Wright #:nodoc:
|
|
46
45
|
# # => "active_model/errors"
|
47
46
|
#
|
48
47
|
# As a rule of thumb you can think of underscore as the inverse
|
49
|
-
# of camelize, though there are cases where that does not hold
|
48
|
+
# of camelize, though there are cases where that does not hold.
|
50
49
|
#
|
50
|
+
# @example
|
51
51
|
# camelize(underscore("SSLError"))
|
52
52
|
# # => "SslError"
|
53
53
|
#
|
54
|
-
#
|
54
|
+
# @return [String] the underscored string
|
55
55
|
def self.underscore(camel_cased_word)
|
56
56
|
word = camel_cased_word.to_s.dup
|
57
57
|
word.gsub!(/::/, '/')
|
@@ -62,15 +62,14 @@ module Wright #:nodoc:
|
|
62
62
|
word
|
63
63
|
end
|
64
64
|
|
65
|
-
#
|
65
|
+
# Converts an underscored_string to UpperCamelCase.
|
66
66
|
#
|
67
67
|
# camelize will also convert '/' to '::' which is useful for
|
68
|
-
#
|
69
|
-
#
|
70
|
-
# s - The String to be camelized.
|
68
|
+
# converting paths to namespaces.
|
71
69
|
#
|
72
|
-
#
|
70
|
+
# @param s [String] the string to be camelized
|
73
71
|
#
|
72
|
+
# @example
|
74
73
|
# camelize("active_record")
|
75
74
|
# # => "ActiveRecord"
|
76
75
|
#
|
@@ -78,25 +77,25 @@ module Wright #:nodoc:
|
|
78
77
|
# # => "ActiveRecord::Errors"
|
79
78
|
#
|
80
79
|
# As a rule of thumb you can think of camelize as the inverse of
|
81
|
-
# underscore, though there are cases where that does not hold
|
80
|
+
# underscore, though there are cases where that does not hold.
|
82
81
|
#
|
83
82
|
# camelize(underscore("SSLError"))
|
84
83
|
# # => "SslError"
|
85
84
|
#
|
86
|
-
#
|
85
|
+
# @return [String] the camelized string
|
87
86
|
def self.camelize(s)
|
88
87
|
s.to_s
|
89
88
|
.gsub(/\/(.?)/) { "::#{Regexp.last_match[1].upcase}" }
|
90
89
|
.gsub(/(?:^|_)(.)/) { Regexp.last_match[1].upcase }
|
91
90
|
end
|
92
91
|
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
# camel_cased_word - The String name of the constant to find.
|
92
|
+
# Finds a constant with the name specified in the argument
|
93
|
+
# string.
|
97
94
|
#
|
98
|
-
#
|
95
|
+
# @param camel_cased_word [String] the name of the constant to
|
96
|
+
# find
|
99
97
|
#
|
98
|
+
# @example
|
100
99
|
# constantize("Module")
|
101
100
|
# # => Module
|
102
101
|
#
|
@@ -105,8 +104,9 @@ module Wright #:nodoc:
|
|
105
104
|
#
|
106
105
|
# The name is assumed to be the one of a top-level constant, no
|
107
106
|
# matter whether it starts with "::" or not. No lexical context
|
108
|
-
# is taken into account
|
107
|
+
# is taken into account.
|
109
108
|
#
|
109
|
+
# @example
|
110
110
|
# C = 'outside'
|
111
111
|
# module M
|
112
112
|
# C = 'inside'
|
@@ -114,9 +114,10 @@ module Wright #:nodoc:
|
|
114
114
|
# constantize("C") # => 'outside', same as ::C
|
115
115
|
# end
|
116
116
|
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
# the constant is unknown
|
117
|
+
# @return [Class] the constant
|
118
|
+
# @raise [NameError] if the constant name is not in CamelCase or
|
119
|
+
# the constant is unknown
|
120
|
+
# @todo Replace this method with Module.const_get in Ruby 2.0.
|
120
121
|
def self.constantize(camel_cased_word)
|
121
122
|
names = camel_cased_word.split('::')
|
122
123
|
names.shift if names.empty? || names.first.empty?
|
@@ -129,13 +130,13 @@ module Wright #:nodoc:
|
|
129
130
|
c
|
130
131
|
end
|
131
132
|
|
132
|
-
#
|
133
|
-
#
|
133
|
+
# Finds a constant with the name specified in the argument
|
134
|
+
# string.
|
134
135
|
#
|
135
|
-
# camel_cased_word
|
136
|
-
#
|
137
|
-
# Examples
|
136
|
+
# @param camel_cased_word [String] the name of the constant to
|
137
|
+
# find
|
138
138
|
#
|
139
|
+
# @example
|
139
140
|
# constantize("Module")
|
140
141
|
# # => Module
|
141
142
|
#
|
@@ -144,8 +145,9 @@ module Wright #:nodoc:
|
|
144
145
|
#
|
145
146
|
# The name is assumed to be the one of a top-level constant, no
|
146
147
|
# matter whether it starts with "::" or not. No lexical context
|
147
|
-
# is taken into account
|
148
|
+
# is taken into account.
|
148
149
|
#
|
150
|
+
# @example
|
149
151
|
# C = 'outside'
|
150
152
|
# module M
|
151
153
|
# C = 'inside'
|
@@ -153,9 +155,7 @@ module Wright #:nodoc:
|
|
153
155
|
# constantize("C") # => 'outside', same as ::C
|
154
156
|
# end
|
155
157
|
#
|
156
|
-
#
|
157
|
-
# constant (or part of it) is unknown.
|
158
|
-
#
|
158
|
+
# @example
|
159
159
|
# safe_constantize("blargle")
|
160
160
|
# # => nil
|
161
161
|
#
|
@@ -165,8 +165,8 @@ module Wright #:nodoc:
|
|
165
165
|
# safe_constantize("UnknownModule::Foo::Bar")
|
166
166
|
# # => nil
|
167
167
|
#
|
168
|
-
#
|
169
|
-
# the constant is unknown
|
168
|
+
# @return [Class, NilClass] the constant or nil if the name is
|
169
|
+
# not in CamelCase or the constant is unknown
|
170
170
|
def self.safe_constantize(camel_cased_word)
|
171
171
|
constantize(camel_cased_word)
|
172
172
|
rescue NameError => e
|
@@ -178,17 +178,16 @@ module Wright #:nodoc:
|
|
178
178
|
raise unless uninitialized_constant_exception
|
179
179
|
end
|
180
180
|
|
181
|
-
#
|
182
|
-
#
|
183
|
-
#
|
184
|
-
# camel_cased_word - The CamelCased String constant name.
|
181
|
+
# Constructs a regular expression that will match a constant
|
182
|
+
# part by part.
|
185
183
|
#
|
186
|
-
#
|
184
|
+
# @param camel_cased_word [String] the CamelCased constant name
|
187
185
|
#
|
186
|
+
# @example
|
188
187
|
# const_regexp("Foo::Bar::Baz")
|
189
188
|
# # => "Foo(::Bar(::Baz)?)?"
|
190
189
|
#
|
191
|
-
#
|
190
|
+
# @return [String] the string to be used as a regular expression
|
192
191
|
def self.const_regexp(camel_cased_word)
|
193
192
|
parts = camel_cased_word.split('::')
|
194
193
|
last = parts.pop
|
data/lib/wright/util/user.rb
CHANGED
@@ -2,53 +2,49 @@ require 'etc'
|
|
2
2
|
|
3
3
|
module Wright
|
4
4
|
module Util
|
5
|
-
#
|
5
|
+
# Various user utility functions.
|
6
6
|
module User
|
7
|
-
#
|
7
|
+
# Returns a user's uid.
|
8
8
|
#
|
9
|
-
# user
|
10
|
-
#
|
11
|
-
# Examples
|
9
|
+
# @param user [String, Integer] the user's name or uid
|
12
10
|
#
|
11
|
+
# @example
|
13
12
|
# Wright::Util::User.user_to_uid('root')
|
14
13
|
# # => 0
|
15
14
|
#
|
16
15
|
# Wright::Util::User.user_to_uid(0)
|
17
16
|
# # => 0
|
18
17
|
#
|
19
|
-
#
|
20
|
-
# nil
|
18
|
+
# @return [Integer] the integer uid of the given user or nil if
|
19
|
+
# user was nil
|
21
20
|
def self.user_to_uid(user)
|
22
21
|
return nil if user.nil?
|
23
22
|
user.is_a?(String) ? Etc.getpwnam(user).uid : user.to_i
|
24
23
|
end
|
25
24
|
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# group - The group name or gid.
|
25
|
+
# Returns a group's gid.
|
29
26
|
#
|
30
|
-
#
|
27
|
+
# @param group [String, Integer] the group's name or gid
|
31
28
|
#
|
29
|
+
# @example
|
32
30
|
# Wright::Util::User.group_to_gid('root')
|
33
31
|
# # => 0
|
34
32
|
#
|
35
33
|
# Wright::Util::User.group_to_gid(0)
|
36
34
|
# # => 0
|
37
35
|
#
|
38
|
-
#
|
39
|
-
# nil
|
36
|
+
# @return [Integer] the integer gid of the given group or nil if
|
37
|
+
# group was nil
|
40
38
|
def self.group_to_gid(group)
|
41
39
|
return nil if group.nil?
|
42
40
|
group.is_a?(String) ? Etc.getgrnam(group).gid : group.to_i
|
43
41
|
end
|
44
42
|
|
45
|
-
#
|
46
|
-
# group.
|
47
|
-
#
|
48
|
-
# owner - The owner string
|
43
|
+
# Splits a colon-separated owner string into owner and group.
|
49
44
|
#
|
50
|
-
#
|
45
|
+
# @param owner [String] the owner string
|
51
46
|
#
|
47
|
+
# @example
|
52
48
|
# Wright::Util::User.owner_to_owner_group('foo:bar')
|
53
49
|
# # => ["foo", "bar"]
|
54
50
|
#
|
@@ -58,10 +54,11 @@ module Wright
|
|
58
54
|
# Wright::Util::User.owner_to_owner_group(23)
|
59
55
|
# # => [23, nil]
|
60
56
|
#
|
61
|
-
#
|
62
|
-
# specified. Non-string owners are
|
63
|
-
#
|
64
|
-
#
|
57
|
+
# @return [Array<(String, String)>] the owner and group. Returns
|
58
|
+
# nil if no group was specified. Non-string owners are
|
59
|
+
# returned unmodified.
|
60
|
+
# @raise [ArgumentError] if the owner string contains more than
|
61
|
+
# one colon
|
65
62
|
def self.owner_to_owner_group(owner)
|
66
63
|
group = nil
|
67
64
|
return [owner, group] unless owner.is_a?(String)
|
data/lib/wright/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wright
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Boehm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -67,19 +67,19 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 10.4.2
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: yard
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.8.7.6
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 0.8.7.6
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -283,3 +283,4 @@ test_files:
|
|
283
283
|
- spec/util/file_spec.rb
|
284
284
|
- spec/util/user_spec.rb
|
285
285
|
- spec/util_spec.rb
|
286
|
+
has_rdoc:
|