wright 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,11 +3,11 @@ require 'fileutils'
3
3
 
4
4
  module Wright
5
5
  class Provider
6
- # Public: Symlink provider. Used as a Provider for Resource::Symlink.
6
+ # Symlink provider. Used as a provider for {Resource::Symlink}.
7
7
  class Symlink < Wright::Provider
8
- # Public: Create or update the Symlink.
8
+ # Creates or updates the symlink.
9
9
  #
10
- # Returns nothing.
10
+ # @return [void]
11
11
  def create
12
12
  if exist?
13
13
  symlink = symlink_to_s(@resource.name, @resource.to)
@@ -20,9 +20,9 @@ module Wright
20
20
  @updated = true
21
21
  end
22
22
 
23
- # Public: Remove the Symlink.
23
+ # Removes the symlink.
24
24
  #
25
- # Returns nothing.
25
+ # @return [void]
26
26
  def remove
27
27
  if ::File.exist?(link_name) && !::File.symlink?(link_name)
28
28
  fail "'#{link_name}' is not a symlink"
@@ -38,11 +38,11 @@ module Wright
38
38
 
39
39
  private
40
40
 
41
- # Internal: Checks if the specified link exists.
41
+ # Checks if the specified link exists.
42
42
  #
43
- # Returns true if the link exists and points to the specified target
44
- # and false otherwise.
45
- def exist? #:doc:
43
+ # Returns true if the link exists and points to the specified
44
+ # target and false otherwise.
45
+ def exist?
46
46
  ::File.symlink?(link_name) &&
47
47
  ::File.readlink(link_name) == link_to
48
48
  end
@@ -4,11 +4,11 @@ require 'wright/logger'
4
4
  require 'wright/dry_run'
5
5
 
6
6
  module Wright
7
- # Public: Resource base class.
7
+ # Resource base class.
8
8
  class Resource
9
- # Public: Initialize a Resource.
9
+ # Initializes a Resource.
10
10
  #
11
- # name - The resource's name.
11
+ # @param name [String] the name of the resource
12
12
  def initialize(name = nil)
13
13
  @name = name
14
14
  @resource_name = Util.class_to_resource_name(self.class).to_sym
@@ -18,16 +18,15 @@ module Wright
18
18
  @ignore_failure = false
19
19
  end
20
20
 
21
- # Public: Get/Set the name Symbol of the method to be run by run_action.
21
+ # @return [Symbol] the name of the method to be run by {#run_action}
22
22
  attr_accessor :action
23
23
 
24
- # Public: Get/Set the ignore_failure attribute.
24
+ # @return [Bool] the ignore_failure attribute
25
25
  attr_accessor :ignore_failure
26
26
 
27
- # Public: Get/Set the resource's name attribute.
28
- #
29
- # Examples
27
+ # @return [String] the resource's name attribute
30
28
  #
29
+ # @example
31
30
  # foo = Wright::Resource::Symlink.new('/tmp/fstab')
32
31
  # foo.name
33
32
  # # => "/tmp/fstab"
@@ -38,22 +37,21 @@ module Wright
38
37
  # # => "/tmp/passwd"
39
38
  attr_accessor :name
40
39
 
41
- # Public: Returns a compact resource name Symbol.
42
- #
43
- # Examples
40
+ # @return [Symbol] a compact resource name
44
41
  #
42
+ # @example
45
43
  # foo = Wright::Resource::Symlink.new
46
44
  # foo.resource_name
47
45
  # # => :symlink
48
46
  attr_reader :resource_name
49
47
 
50
- # Public: Set an update action for a resource.
48
+ # Sets an update action for a resource.
51
49
  #
52
- # on_update - The block that is called if the resource is
53
- # updated. Has to respond to :call.
50
+ # @param on_update [Proc, #call] the block that is called when the
51
+ # resource is updated.
54
52
  #
55
- # Returns nothing.
56
- # Raises ArgumentError if on_update is not callable
53
+ # @return [void]
54
+ # @raise [ArgumentError] if on_update is not callable
57
55
  def on_update=(on_update)
58
56
  if on_update.respond_to?(:call) || on_update.nil?
59
57
  @on_update = on_update
@@ -62,28 +60,29 @@ module Wright
62
60
  end
63
61
  end
64
62
 
65
- # Public: Run the resource's current action.
66
- #
67
- # Examples
63
+ # Runs the resource's current action.
68
64
  #
65
+ # @example
69
66
  # fstab = Wright::Resource::Symlink.new('/tmp/fstab')
70
67
  # fstab.action = :remove
71
68
  # fstab.run_action
69
+ #
70
+ # @return the return value of the current action
72
71
  def run_action
73
72
  send @action if @action
74
73
  end
75
74
 
76
75
  private
77
76
 
78
- # Public: Mark a code block that might update a resource.
77
+ # @api public
78
+ # Marks a code block that might update a resource.
79
79
  #
80
80
  # Usually this method is called in the definition of a new
81
81
  # resource class in order to mark those methods that should be
82
82
  # able to trigger update actions. Runs the current update action
83
83
  # if the provider was updated by the block method.
84
84
  #
85
- # Examples
86
- #
85
+ # @example
87
86
  # class BalloonAnimal < Wright::Provider
88
87
  # def inflate
89
88
  # puts "It's a giraffe!"
@@ -101,8 +100,9 @@ module Wright
101
100
  # balloon = Balloon.new.inflate
102
101
  # # => true
103
102
  #
104
- # Returns true if the provider was updated and false otherwise.
105
- def might_update_resource #:doc:
103
+ # @return [Bool] true if the provider was updated and false
104
+ # otherwise
105
+ def might_update_resource
106
106
  begin
107
107
  yield
108
108
  rescue => e
@@ -3,16 +3,15 @@ require 'wright/dsl'
3
3
 
4
4
  module Wright
5
5
  class Resource
6
- # Public: Directory resource, represents a directory.
7
- #
8
- # Examples
6
+ # Directory resource, represents a directory.
9
7
  #
8
+ # @example
10
9
  # dir = Wright::Resource::Directory.new('/tmp/foobar')
11
10
  # dir.create
12
11
  class Directory < Wright::Resource
13
- # Public: Initialize a Directory.
12
+ # Initializes a Directory.
14
13
  #
15
- # name - The directory's name.
14
+ # @param name [String] the directory's name
16
15
  def initialize(name)
17
16
  super
18
17
  @mode = nil
@@ -21,13 +20,13 @@ module Wright
21
20
  @action = :create
22
21
  end
23
22
 
24
- # Public: Get/Set the directory's mode.
23
+ # @return [String, Integer] the directory's mode
25
24
  attr_accessor :mode
26
25
 
27
- # Public: Get the directory's owner.
26
+ # @return [String] the directory's owner
28
27
  attr_reader :owner
29
28
 
30
- # Public: Set the directory's owner.
29
+ # Sets the directory's owner.
31
30
  def owner=(owner)
32
31
  target_owner, target_group =
33
32
  Wright::Util::User.owner_to_owner_group(owner)
@@ -35,26 +34,28 @@ module Wright
35
34
  @group = target_group unless target_group.nil?
36
35
  end
37
36
 
38
- # Public: Get the directory's group.
37
+ # @return [String] the directory's group
39
38
  attr_reader :group
40
39
 
41
- # Public: Set the directory's group
40
+ # Sets the directory's group.
42
41
  def group=(group)
43
42
  @group = Wright::Util::User.group_to_gid(group)
44
43
  end
45
44
 
46
- # Public: Create or update the directory.
45
+ # Creates or updates the directory.
47
46
  #
48
- # Returns true if the directory was updated and false otherwise.
47
+ # @return [Bool] true if the directory was updated and false
48
+ # otherwise
49
49
  def create
50
50
  might_update_resource do
51
51
  @provider.create
52
52
  end
53
53
  end
54
54
 
55
- # Public: Remove the directory.
55
+ # Removes the directory.
56
56
  #
57
- # Returns true if the directory was updated and false otherwise.
57
+ # @return [Bool] true if the directory was updated and false
58
+ # otherwise
58
59
  def remove
59
60
  might_update_resource do
60
61
  @provider.remove
@@ -3,29 +3,28 @@ require 'wright/dsl'
3
3
 
4
4
  module Wright
5
5
  class Resource
6
- # Public: Symlink resource, represents a symlink.
7
- #
8
- # Examples
6
+ # Symlink resource, represents a symlink.
9
7
  #
8
+ # @example
10
9
  # file = Wright::Resource::File.new('/tmp/foo')
11
10
  # file.content = 'bar'
12
11
  # file.create
13
12
  class File < Wright::Resource
14
- # Public: Get/Set the file's content.
13
+ # @return [String] the file's intended content
15
14
  attr_accessor :content
16
15
 
17
- # Public: Get/Set the file's group.
16
+ # @return [String] the file's intended group.
18
17
  attr_accessor :group
19
18
 
20
- # Public: Get/Set the file's mode.
19
+ # @return [String, Integer] the file's intended mode
21
20
  attr_accessor :mode
22
21
 
23
- # Public: Get the file's owner.
22
+ # @return [String] the file's intended owner
24
23
  attr_reader :owner
25
24
 
26
- # Public: Initialize a File.
25
+ # Initializes a File.
27
26
  #
28
- # name - The file's name.
27
+ # @param name [String] the file's name
29
28
  def initialize(name)
30
29
  super
31
30
  @content = nil
@@ -35,7 +34,7 @@ module Wright
35
34
  @action = :create
36
35
  end
37
36
 
38
- # Public: Set the file's owner.
37
+ # Sets the file's owner.
39
38
  def owner=(owner)
40
39
  target_owner, target_group =
41
40
  Wright::Util::User.owner_to_owner_group(owner)
@@ -43,18 +42,20 @@ module Wright
43
42
  @group = target_group unless target_group.nil?
44
43
  end
45
44
 
46
- # Public: Create or update the File.
45
+ # Creates or updates the file.
47
46
  #
48
- # Returns true if the file was updated and false otherwise.
47
+ # @return [Bool] true if the file was updated and false
48
+ # otherwise
49
49
  def create
50
50
  might_update_resource do
51
51
  @provider.create
52
52
  end
53
53
  end
54
54
 
55
- # Public: Remove the File.
55
+ # Removes the file.
56
56
  #
57
- # Returns true if the file was updated and false otherwise.
57
+ # @return [Bool] true if the file was updated and false
58
+ # otherwise
58
59
  def remove
59
60
  might_update_resource do
60
61
  @provider.remove
@@ -3,10 +3,9 @@ require 'wright/dsl'
3
3
 
4
4
  module Wright
5
5
  class Resource
6
- # Public: Package resource, represents a package.
7
- #
8
- # Examples
6
+ # Package resource, represents a package.
9
7
  #
8
+ # @example
10
9
  # vim = Wright::Resource::Package.new('vim')
11
10
  # vim.installed_versions
12
11
  # # => []
@@ -21,42 +20,44 @@ module Wright
21
20
  # htop.installed_versions
22
21
  # # => []
23
22
  class Package < Wright::Resource
24
- # Public: Get/Set the package version to install/remove.
23
+ # @return [String] the package version to install or remove
25
24
  attr_accessor :version
26
25
 
27
- # Public: Initialize a Package.
26
+ # Initializes a Package.
28
27
  #
29
- # name - The package name.
28
+ # @param name [String] the package's name
30
29
  def initialize(name)
31
30
  super
32
31
  @version = nil
33
32
  @action = :install
34
33
  end
35
34
 
36
- # Public: Get the installed version of a package.
37
- #
38
- # Returns an array of installed package version Strings.
35
+ # @return [Array<String>] the installed package versions
39
36
  def installed_versions
40
37
  @provider.installed_versions
41
38
  end
42
39
 
43
- # Public: Install the Package.
40
+ # Installs the Package.
44
41
  #
45
- # Returns true if the package was updated and false otherwise.
42
+ # @return [Bool] true if the package was updated and false
43
+ # otherwise
46
44
  def install
47
45
  might_update_resource do
48
46
  @provider.install
49
47
  end
50
48
  end
51
49
 
52
- # Public: Remove the Package.
50
+ # Removes the Package.
53
51
  #
54
- # Returns true if the package was updated and false otherwise.
52
+ # @return [Bool] true if the package was updated and false
53
+ # otherwise
55
54
  def remove
56
55
  might_update_resource do
57
56
  @provider.remove
58
57
  end
59
58
  end
59
+
60
+ alias_method :uninstall, :remove
60
61
  end
61
62
  end
62
63
  end
@@ -3,38 +3,39 @@ require 'wright/dsl'
3
3
 
4
4
  module Wright
5
5
  class Resource
6
- # Public: Symlink resource, represents a symlink.
7
- #
8
- # Examples
6
+ # Symlink resource, represents a symlink.
9
7
  #
8
+ # @example
10
9
  # link = Wright::Resource::Symlink.new('/tmp/fstab')
11
10
  # link.to = '/etc/fstab'
12
11
  # link.create
13
12
  class Symlink < Wright::Resource
14
- # Public: Initialize a Symlink.
13
+ # Initializes a Symlink.
15
14
  #
16
- # name - The link's name.
15
+ # @param name [String] the symlink's name
17
16
  def initialize(name)
18
17
  super
19
18
  @to = nil
20
19
  @action = :create
21
20
  end
22
21
 
23
- # Public: Get/Set the link's target.
22
+ # @return [String] the symlink's intended target
24
23
  attr_accessor :to
25
24
 
26
- # Public: Create or update the Symlink.
25
+ # Creates or updates the symlink.
27
26
  #
28
- # Returns true if the symlink was updated and false otherwise.
27
+ # @return [Bool] true if the symlink was updated and false
28
+ # otherwise
29
29
  def create
30
30
  might_update_resource do
31
31
  @provider.create
32
32
  end
33
33
  end
34
34
 
35
- # Public: Remove the Symlink.
35
+ # Removes the symlink.
36
36
  #
37
- # Returns true if the symlink was updated and false otherwise.
37
+ # @return [Bool] true if the symlink was updated and false
38
+ # otherwise
38
39
  def remove
39
40
  might_update_resource do
40
41
  @provider.remove
data/lib/wright/util.rb CHANGED
@@ -1,38 +1,37 @@
1
1
  require 'wright/util/stolen_from_activesupport'
2
2
 
3
3
  module Wright
4
- # Internal: Various utility functions.
4
+ # @api private
5
+ # Various utility functions.
5
6
  module Util
6
- # Internal: Get the resource name corresponding to a class.
7
+ # Converts a class constant into its corresponding resource name.
7
8
  #
8
- # klass - The class constant for which to get the resource name.
9
- #
10
- # Examples
9
+ # @param klass [Class] the class constant
11
10
  #
11
+ # @example
12
12
  # Wright::Util.class_to_resource_name(Wright::Resource::Package)
13
13
  # # => "package"
14
14
  #
15
15
  # Wright::Util.class_to_resource_name(Foo::Bar::BazQux)
16
16
  # # => "baz_qux"
17
17
  #
18
- # Returns the String resource name of the given class.
18
+ # @return [String] the resource name of the given class
19
19
  def self.class_to_resource_name(klass)
20
20
  ActiveSupport.underscore(klass.name).split('/').last
21
21
  end
22
22
 
23
- # Internal: Get the class name corresponding to a file path.
24
- #
25
- # filename - The filename for which to get the class name.
23
+ # Converts a file path into its corresponding class name.
26
24
  #
27
- # Examples
25
+ # @param filename [String] the filename
28
26
  #
29
- # Wright::Util.filename_to_classname("foo/bar/baz.rb")
27
+ # @example
28
+ # Wright::Util.filename_to_classname('foo/bar/baz.rb')
30
29
  # # => "Foo::Bar::Baz"
31
30
  #
32
- # Wright::Util.filename_to_classname("foo/bar/")
31
+ # Wright::Util.filename_to_classname('foo/bar/')
33
32
  # # => "Foo::Bar"
34
33
  #
35
- # Returns the String class name for the given filename.
34
+ # @return [String] the class name for the given filename
36
35
  def self.filename_to_classname(filename)
37
36
  ActiveSupport.camelize(filename.chomp('.rb').chomp('/'))
38
37
  end
@@ -45,18 +44,17 @@ module Wright
45
44
  end
46
45
  private_class_method :distro
47
46
 
48
- # Internal: Get the system's OS family.
49
- #
50
- # Examples
47
+ # Determines the system's OS family.
51
48
  #
49
+ # @example
52
50
  # Wright::Util.os_family
53
51
  # # => "debian"
54
- #
52
+ # @example
55
53
  # Wright::Util.os_family
56
54
  # # => "macosx"
57
55
  #
58
- # Returns the String system OS family (base distribution for
59
- # GNU/Linux systems) or 'other' for unknown operating systems.
56
+ # @return [String] the system's OS family (base distribution for
57
+ # GNU/Linux systems) or 'other' for unknown operating systems
60
58
  def self.os_family
61
59
  system_arch = RbConfig::CONFIG['target_os']
62
60
  case system_arch