automateit 0.71226.1 → 0.71230

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGES.txt +13 -1
  3. data/Hoe.rake +1 -2
  4. data/Rakefile +13 -9
  5. data/TODO.txt +4 -1
  6. data/bin/aifield +0 -11
  7. data/bin/aitag +16 -23
  8. data/helpers/cpan_wrapper.pl +138 -16
  9. data/lib/automateit.rb +1 -15
  10. data/lib/automateit/account_manager/base.rb +8 -4
  11. data/lib/automateit/address_manager/freebsd.rb +6 -3
  12. data/lib/automateit/address_manager/openbsd.rb +6 -3
  13. data/lib/automateit/edit_manager.rb +13 -5
  14. data/lib/automateit/package_manager.rb +16 -8
  15. data/lib/automateit/package_manager/cpan.rb +4 -6
  16. data/lib/automateit/platform_manager/lsb.rb +15 -11
  17. data/lib/automateit/root.rb +1 -1
  18. data/lib/automateit/service_manager/sysv.rb +6 -3
  19. data/lib/automateit/template_manager/base.rb +30 -26
  20. data/lib/inactive_support.rb +50 -0
  21. data/lib/inactive_support/basic_object.rb +5 -0
  22. data/lib/inactive_support/clean_logger.rb +127 -0
  23. data/lib/inactive_support/core_ext/array/extract_options.rb +19 -0
  24. data/lib/inactive_support/core_ext/blank.rb +50 -0
  25. data/lib/inactive_support/core_ext/class/attribute_accessors.rb +48 -0
  26. data/lib/inactive_support/core_ext/class/inheritable_attributes.rb +140 -0
  27. data/lib/inactive_support/core_ext/enumerable.rb +63 -0
  28. data/lib/inactive_support/core_ext/hash/keys.rb +54 -0
  29. data/lib/inactive_support/core_ext/module/aliasing.rb +70 -0
  30. data/lib/inactive_support/core_ext/numeric/time.rb +91 -0
  31. data/lib/inactive_support/core_ext/string/inflections.rb +153 -0
  32. data/lib/inactive_support/core_ext/symbol.rb +14 -0
  33. data/lib/inactive_support/core_ext/time/conversions.rb +94 -0
  34. data/lib/inactive_support/duration.rb +96 -0
  35. data/lib/inactive_support/inflections.rb +53 -0
  36. data/lib/inactive_support/inflector.rb +282 -0
  37. data/lib/nitpick.rb +8 -4
  38. data/spec/integration/package_manager_spec.rb +1 -1
  39. data/spec/integration/platform_manager_spec.rb +0 -16
  40. data/spec/unit/edit_manager_spec.rb +1 -0
  41. data/spec/unit/package_manager_spec.rb +1 -0
  42. metadata +19 -23
  43. metadata.gz.sig +0 -0
  44. data/helpers/cpan_install.pl +0 -59
  45. data/helpers/cpan_is_installed.pl +0 -37
  46. data/helpers/cpan_uninstall.pl +0 -58
@@ -0,0 +1,91 @@
1
+ module InactiveSupport #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module Numeric #:nodoc:
4
+ # Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years.
5
+ #
6
+ # These methods use Time#advance for precise date calculations when using from_now, ago, etc.
7
+ # as well as adding or subtracting their results from a Time object. For example:
8
+ #
9
+ # # equivalent to Time.now.advance(:months => 1)
10
+ # 1.month.from_now
11
+ #
12
+ # # equivalent to Time.now.advance(:years => 2)
13
+ # 2.years.from_now
14
+ #
15
+ # # equivalent to Time.now.advance(:months => 4, :years => 5)
16
+ # (4.months + 5.years).from_now
17
+ #
18
+ # While these methods provide precise calculation when used as in the examples above, care
19
+ # should be taken to note that this is not true if the result of `months', `years', etc is
20
+ # converted before use:
21
+ #
22
+ # # equivalent to 30.days.to_i.from_now
23
+ # 1.month.to_i.from_now
24
+ #
25
+ # # equivalent to 365.25.days.to_f.from_now
26
+ # 1.year.to_f.from_now
27
+ #
28
+ # In such cases, Ruby's core
29
+ # Date[http://stdlib.rubyonrails.org/libdoc/date/rdoc/index.html] and
30
+ # Time[http://stdlib.rubyonrails.org/libdoc/time/rdoc/index.html] should be used for precision
31
+ # date and time arithmetic
32
+ module Time
33
+ def seconds
34
+ InactiveSupport::Duration.new(self, [[:seconds, self]])
35
+ end
36
+ alias :second :seconds
37
+
38
+ def minutes
39
+ InactiveSupport::Duration.new(self * 60, [[:seconds, self * 60]])
40
+ end
41
+ alias :minute :minutes
42
+
43
+ def hours
44
+ InactiveSupport::Duration.new(self * 3600, [[:seconds, self * 3600]])
45
+ end
46
+ alias :hour :hours
47
+
48
+ def days
49
+ InactiveSupport::Duration.new(self * 24.hours, [[:days, self]])
50
+ end
51
+ alias :day :days
52
+
53
+ def weeks
54
+ InactiveSupport::Duration.new(self * 7.days, [[:days, self * 7]])
55
+ end
56
+ alias :week :weeks
57
+
58
+ def fortnights
59
+ InactiveSupport::Duration.new(self * 2.weeks, [[:days, self * 14]])
60
+ end
61
+ alias :fortnight :fortnights
62
+
63
+ def months
64
+ InactiveSupport::Duration.new(self * 30.days, [[:months, self]])
65
+ end
66
+ alias :month :months
67
+
68
+ def years
69
+ InactiveSupport::Duration.new(self * 365.25.days, [[:years, self]])
70
+ end
71
+ alias :year :years
72
+
73
+ # Reads best without arguments: 10.minutes.ago
74
+ def ago(time = ::Time.now)
75
+ time - self
76
+ end
77
+
78
+ # Reads best with argument: 10.minutes.until(time)
79
+ alias :until :ago
80
+
81
+ # Reads best with argument: 10.minutes.since(time)
82
+ def since(time = ::Time.now)
83
+ time + self
84
+ end
85
+
86
+ # Reads best without arguments: 10.minutes.from_now
87
+ alias :from_now :since
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,153 @@
1
+ require 'inactive_support/inflector'
2
+
3
+ module InactiveSupport #:nodoc:
4
+ module CoreExtensions #:nodoc:
5
+ module String #:nodoc:
6
+ # String inflections define new methods on the String class to transform names for different purposes.
7
+ # For instance, you can figure out the name of a database from the name of a class.
8
+ # "ScaleScore".tableize => "scale_scores"
9
+ module Inflections
10
+ # Returns the plural form of the word in the string.
11
+ #
12
+ # Examples
13
+ # "post".pluralize #=> "posts"
14
+ # "octopus".pluralize #=> "octopi"
15
+ # "sheep".pluralize #=> "sheep"
16
+ # "words".pluralize #=> "words"
17
+ # "the blue mailman".pluralize #=> "the blue mailmen"
18
+ # "CamelOctopus".pluralize #=> "CamelOctopi"
19
+ def pluralize
20
+ Inflector.pluralize(self)
21
+ end
22
+
23
+ # The reverse of pluralize, returns the singular form of a word in a string.
24
+ #
25
+ # Examples
26
+ # "posts".singularize #=> "post"
27
+ # "octopi".singularize #=> "octopus"
28
+ # "sheep".singluarize #=> "sheep"
29
+ # "word".singluarize #=> "word"
30
+ # "the blue mailmen".singularize #=> "the blue mailman"
31
+ # "CamelOctopi".singularize #=> "CamelOctopus"
32
+ def singularize
33
+ Inflector.singularize(self)
34
+ end
35
+
36
+ # By default, camelize converts strings to UpperCamelCase. If the argument to camelize
37
+ # is set to ":lower" then camelize produces lowerCamelCase.
38
+ #
39
+ # camelize will also convert '/' to '::' which is useful for converting paths to namespaces
40
+ #
41
+ # Examples
42
+ # "active_record".camelize #=> "ActiveRecord"
43
+ # "active_record".camelize(:lower) #=> "activeRecord"
44
+ # "active_record/errors".camelize #=> "ActiveRecord::Errors"
45
+ # "active_record/errors".camelize(:lower) #=> "activeRecord::Errors"
46
+ def camelize(first_letter = :upper)
47
+ case first_letter
48
+ when :upper then Inflector.camelize(self, true)
49
+ when :lower then Inflector.camelize(self, false)
50
+ end
51
+ end
52
+ alias_method :camelcase, :camelize
53
+
54
+ # Capitalizes all the words and replaces some characters in the string to create
55
+ # a nicer looking title. Titleize is meant for creating pretty output. It is not
56
+ # used in the Rails internals.
57
+ #
58
+ # titleize is also aliased as as titlecase
59
+ #
60
+ # Examples
61
+ # "man from the boondocks".titleize #=> "Man From The Boondocks"
62
+ # "x-men: the last stand".titleize #=> "X Men: The Last Stand"
63
+ def titleize
64
+ Inflector.titleize(self)
65
+ end
66
+ alias_method :titlecase, :titleize
67
+
68
+ # The reverse of +camelize+. Makes an underscored form from the expression in the string.
69
+ #
70
+ # Changes '::' to '/' to convert namespaces to paths.
71
+ #
72
+ # Examples
73
+ # "ActiveRecord".underscore #=> "active_record"
74
+ # "ActiveRecord::Errors".underscore #=> active_record/errors
75
+ def underscore
76
+ Inflector.underscore(self)
77
+ end
78
+
79
+ # Replaces underscores with dashes in the string.
80
+ #
81
+ # Example
82
+ # "puni_puni" #=> "puni-puni"
83
+ def dasherize
84
+ Inflector.dasherize(self)
85
+ end
86
+
87
+ # Removes the module part from the expression in the string
88
+ #
89
+ # Examples
90
+ # "ActiveRecord::CoreExtensions::String::Inflections".demodulize #=> "Inflections"
91
+ # "Inflections".demodulize #=> "Inflections"
92
+ def demodulize
93
+ Inflector.demodulize(self)
94
+ end
95
+
96
+ # Create the name of a table like Rails does for models to table names. This method
97
+ # uses the pluralize method on the last word in the string.
98
+ #
99
+ # Examples
100
+ # "RawScaledScorer".tableize #=> "raw_scaled_scorers"
101
+ # "egg_and_ham".tableize #=> "egg_and_hams"
102
+ # "fancyCategory".tableize #=> "fancy_categories"
103
+ def tableize
104
+ Inflector.tableize(self)
105
+ end
106
+
107
+ # Create a class name from a table name like Rails does for table names to models.
108
+ # Note that this returns a string and not a Class. (To convert to an actual class
109
+ # follow classify with constantize.)
110
+ #
111
+ # Examples
112
+ # "egg_and_hams".classify #=> "EggAndHam"
113
+ # "post".classify #=> "Post"
114
+ def classify
115
+ Inflector.classify(self)
116
+ end
117
+
118
+ # Capitalizes the first word and turns underscores into spaces and strips _id.
119
+ # Like titleize, this is meant for creating pretty output.
120
+ #
121
+ # Examples
122
+ # "employee_salary" #=> "Employee salary"
123
+ # "author_id" #=> "Author"
124
+ def humanize
125
+ Inflector.humanize(self)
126
+ end
127
+
128
+ # Creates a foreign key name from a class name.
129
+ # +separate_class_name_and_id_with_underscore+ sets whether
130
+ # the method should put '_' between the name and 'id'.
131
+ #
132
+ # Examples
133
+ # "Message".foreign_key #=> "message_id"
134
+ # "Message".foreign_key(false) #=> "messageid"
135
+ # "Admin::Post".foreign_key #=> "post_id"
136
+ def foreign_key(separate_class_name_and_id_with_underscore = true)
137
+ Inflector.foreign_key(self, separate_class_name_and_id_with_underscore)
138
+ end
139
+
140
+ # Constantize tries to find a declared constant with the name specified
141
+ # in the string. It raises a NameError when the name is not in CamelCase
142
+ # or is not initialized.
143
+ #
144
+ # Examples
145
+ # "Module".constantize #=> Module
146
+ # "Class".constantize #=> Class
147
+ def constantize
148
+ Inflector.constantize(self)
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,14 @@
1
+ unless :test.respond_to?(:to_proc)
2
+ class Symbol
3
+ # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples:
4
+ #
5
+ # # The same as people.collect { |p| p.name }
6
+ # people.collect(&:name)
7
+ #
8
+ # # The same as people.select { |p| p.manager? }.collect { |p| p.salary }
9
+ # people.select(&:manager?).collect(&:salary)
10
+ def to_proc
11
+ Proc.new { |*args| args.shift.__send__(self, *args) }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,94 @@
1
+ module InactiveSupport #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module Time #:nodoc:
4
+ # Getting times in different convenient string representations and other objects
5
+ module Conversions
6
+ DATE_FORMATS = {
7
+ :db => "%Y-%m-%d %H:%M:%S",
8
+ :time => "%H:%M",
9
+ :short => "%d %b %H:%M",
10
+ :long => "%B %d, %Y %H:%M",
11
+ :long_ordinal => lambda { |time| time.strftime("%B #{time.day.ordinalize}, %Y %H:%M") },
12
+ :rfc822 => "%a, %d %b %Y %H:%M:%S %z"
13
+ }
14
+
15
+ def self.included(base)
16
+ base.class_eval do
17
+ alias_method :to_default_s, :to_s
18
+ alias_method :to_s, :to_formatted_s
19
+ end
20
+ end
21
+
22
+ # Convert to a formatted string - see DATE_FORMATS for predefined formats.
23
+ # You can also add your own formats to the DATE_FORMATS constant and use them with this method.
24
+ #
25
+ # This method is also aliased as <tt>to_s</tt>.
26
+ #
27
+ # ==== Examples:
28
+ # time = Time.now # => Thu Jan 18 06:10:17 CST 2007
29
+ #
30
+ # time.to_formatted_s(:time) # => "06:10:17"
31
+ # time.to_s(:time) # => "06:10:17"
32
+ #
33
+ # time.to_formatted_s(:db) # => "2007-01-18 06:10:17"
34
+ # time.to_formatted_s(:short) # => "18 Jan 06:10"
35
+ # time.to_formatted_s(:long) # => "January 18, 2007 06:10"
36
+ # time.to_formatted_s(:long_ordinal) # => "January 18th, 2007 06:10"
37
+ # time.to_formatted_s(:rfc822) # => "Thu, 18 Jan 2007 06:10:17 -0600"
38
+ def to_formatted_s(format = :default)
39
+ if formatter = DATE_FORMATS[format]
40
+ if formatter.respond_to?(:call)
41
+ formatter.call(self).to_s
42
+ else
43
+ strftime(formatter)
44
+ end
45
+ else
46
+ to_default_s
47
+ end
48
+ end
49
+
50
+ # Convert a Time object to a Date, dropping hour, minute, and second precision.
51
+ #
52
+ # ==== Examples
53
+ # my_time = Time.now
54
+ # # => Mon Nov 12 22:59:51 -0500 2007
55
+ #
56
+ # my_time.to_date
57
+ # #=> Mon, 12 Nov 2007
58
+ #
59
+ # your_time = Time.parse("1/13/2009 1:13:03 P.M.")
60
+ # # => Tue Jan 13 13:13:03 -0500 2009
61
+ #
62
+ # your_time.to_date
63
+ # # => Tue, 13 Jan 2009
64
+ def to_date
65
+ ::Date.new(year, month, day)
66
+ end
67
+
68
+ # A method to keep Time, Date and DateTime instances interchangeable on conversions.
69
+ # In this case, it simply returns +self+.
70
+ def to_time
71
+ self
72
+ end
73
+
74
+ # Converts a Time instance to a Ruby DateTime instance, preserving UTC offset.
75
+ #
76
+ # ==== Examples
77
+ # my_time = Time.now
78
+ # # => Mon Nov 12 23:04:21 -0500 2007
79
+ #
80
+ # my_time.to_datetime
81
+ # # => Mon, 12 Nov 2007 23:04:21 -0500
82
+ #
83
+ # your_time = Time.parse("1/13/2009 1:13:03 P.M.")
84
+ # # => Tue Jan 13 13:13:03 -0500 2009
85
+ #
86
+ # your_time.to_datetime
87
+ # # => Tue, 13 Jan 2009 13:13:03 -0500
88
+ def to_datetime
89
+ ::DateTime.civil(year, month, day, hour, min, sec, Rational(utc_offset, 86400))
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,96 @@
1
+ module InactiveSupport
2
+ # Provides accurate date and time measurements using Date#advance and
3
+ # Time#advance, respectively. It mainly supports the methods on Numeric,
4
+ # such as in this example:
5
+ #
6
+ # 1.month.ago # equivalent to Time.now.advance(:months => -1)
7
+ class Duration < BasicObject
8
+ attr_accessor :value, :parts
9
+
10
+ def initialize(value, parts) #:nodoc:
11
+ @value, @parts = value, parts
12
+ end
13
+
14
+ # Adds another Duration or a Numeric to this Duration. Numeric values
15
+ # are treated as seconds.
16
+ def +(other)
17
+ if Duration === other
18
+ Duration.new(value + other.value, @parts + other.parts)
19
+ else
20
+ Duration.new(value + other, @parts + [[:seconds, other]])
21
+ end
22
+ end
23
+
24
+ # Subtracts another Duration or a Numeric from this Duration. Numeric
25
+ # values are treated as seconds.
26
+ def -(other)
27
+ self + (-other)
28
+ end
29
+
30
+ def -@ #:nodoc:
31
+ Duration.new(-value, parts.map { |type,number| [type, -number] })
32
+ end
33
+
34
+ def is_a?(klass) #:nodoc:
35
+ klass == Duration || super
36
+ end
37
+
38
+ # Returns true if <tt>other</tt> is also a Duration instance with the
39
+ # same <tt>value</tt>, or if <tt>other == value</tt>.
40
+ def ==(other)
41
+ if Duration === other
42
+ other.value == value
43
+ else
44
+ other == value
45
+ end
46
+ end
47
+
48
+ def self.===(other) #:nodoc:
49
+ other.is_a?(Duration) rescue super
50
+ end
51
+
52
+ # Calculates a new Time or Date that is as far in the future
53
+ # as this Duration represents.
54
+ def since(time = ::Time.now)
55
+ sum(1, time)
56
+ end
57
+ alias :from_now :since
58
+
59
+ # Calculates a new Time or Date that is as far in the past
60
+ # as this Duration represents.
61
+ def ago(time = ::Time.now)
62
+ sum(-1, time)
63
+ end
64
+ alias :until :ago
65
+
66
+ def inspect #:nodoc:
67
+ consolidated = parts.inject(::Hash.new(0)) { |h,part| h[part.first] += part.last; h }
68
+ [:years, :months, :days, :minutes, :seconds].map do |length|
69
+ n = consolidated[length]
70
+ "#{n} #{n == 1 ? length.to_s.singularize : length.to_s}" if n.nonzero?
71
+ end.compact.to_sentence
72
+ end
73
+
74
+ protected
75
+
76
+ def sum(sign, time = ::Time.now) #:nodoc:
77
+ parts.inject(time) do |t,(type,number)|
78
+ if t.acts_like?(:time) || t.acts_like?(:date)
79
+ if type == :seconds
80
+ t.since(sign * number)
81
+ else
82
+ t.advance(type => sign * number)
83
+ end
84
+ else
85
+ raise ArgumentError, "expected a time or date, got #{time.inspect}"
86
+ end
87
+ end
88
+ end
89
+
90
+ private
91
+
92
+ def method_missing(method, *args, &block) #:nodoc:
93
+ value.send(method, *args)
94
+ end
95
+ end
96
+ end