bozo-scripts 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,155 +1,155 @@
1
- module Bozo
2
-
3
- # Class for generating configuration objects.
4
- class Configuration
5
-
6
- # Create a new instance.
7
- def initialize
8
- @root = ConfigurationGroup.new
9
- @group_stack = [@root]
10
- end
11
-
12
- # Begin the definition of a group with the given name.
13
- #
14
- # @param [Symbol] name
15
- # The name of the group.
16
- def group(name)
17
- new_group = @group_stack.last.ensure_child name
18
- @group_stack.push new_group
19
- yield
20
- @group_stack.pop
21
- end
22
-
23
- # Set the value of the given key within the active group.
24
- #
25
- # @param [Symbol] key
26
- # The key to set the value of within the active group.
27
- # @param [Object] value
28
- # The value to set the key to within the active group.
29
- def set(key, value)
30
- @group_stack.last.set_value(key, value)
31
- end
32
-
33
- # Returns the configuration value for the key
34
- #
35
- # @param [Symbol] key
36
- def [](key)
37
- @root[key]
38
- end
39
-
40
- # Load the specified file as an additional configuration file.
41
- #
42
- # == Usage
43
- #
44
- # Configuration files specify a hash of hashes in a more readable format.
45
- # For example:
46
- #
47
- # group :example do
48
- # set :one, 'foo'
49
- # set :two, 'bar'
50
- # end
51
- #
52
- # Internally creates a hash like:
53
- #
54
- # {:example => {:one => 'foo', :two => 'bar'}}
55
- #
56
- # A configuration file can overwrite the values specified by a preceding one
57
- # without error. Groups can be opened and closed as desired and nesting
58
- # groups is possible.
59
- #
60
- # @param [String] path
61
- # The path of the configuration file.
62
- def load(path)
63
- instance_eval IO.read(path), path
64
- end
65
-
66
- # Yields the internal binding of the configuration to the given block.
67
- #
68
- # @param [Proc] block
69
- # The block to yield the configuration's internal binding to.
70
- def apply(&block)
71
- @root.apply(block)
72
- end
73
-
74
- # Return the current state of the configuration.
75
- def inspect
76
- @root.inspect
77
- end
78
-
79
- private
80
-
81
- # Class for controlling the creation and retrieval of configuration
82
- # groups and values.
83
- #
84
- # Should not be used outside of this class.
85
- class ConfigurationGroup # :nodoc:
86
-
87
- # Create a new instance.
88
- def initialize(*parents)
89
- @parents = parents
90
- @hash = {}
91
- end
92
-
93
- # Enables the fluent retrieval of groups within the hash.
94
- def method_missing(sym, *args, &block)
95
- raise missing_child sym unless @hash.key? sym
96
- @hash[sym]
97
- end
98
-
99
- # Returns the configuration value for the key
100
- #
101
- # @param [Symbol] key
102
- def [](key)
103
- @hash[key]
104
- end
105
-
106
- # Ensures the hash contains a child hash for the specified key and
107
- # returns it.
108
- #
109
- # @param [Symbol] key
110
- # The key that must contain a child hash.
111
- def ensure_child(key)
112
- @hash[key] = ConfigurationGroup.new(@parents + [key]) unless @hash.key? key
113
- @hash[key]
114
- end
115
-
116
- # Sets the value of the specified key.
117
- #
118
- # @param [Symbol] key
119
- # The key to set the value of.
120
- # @param [Object] value
121
- # The value to set for the specified key.
122
- def set_value(key, value)
123
- @hash[key] = value
124
- end
125
-
126
- # Yields the internal binding of the configuration group to the given
127
- # block.
128
- #
129
- # @param [Proc] block
130
- # The block to yield the internal binding to.
131
- def apply(block)
132
- block.call(binding)
133
- end
134
-
135
- # Return the current state of the configuration.
136
- def inspect
137
- @hash.inspect
138
- end
139
-
140
- private
141
-
142
- # Create a new error specifying that an attempt was made to retrieve a
143
- # child that does not exist.
144
- #
145
- # @param [Symbol] sym
146
- # The key of the requested child.
147
- def missing_child(sym)
148
- Bozo::ConfigurationError.new "#{@parents.any? ? @parents.join('.') : 'Root'} does not contain a value or group called '#{sym}' - known keys: #{@hash.keys.join(', ')}"
149
- end
150
-
151
- end
152
-
153
- end
154
-
1
+ module Bozo
2
+
3
+ # Class for generating configuration objects.
4
+ class Configuration
5
+
6
+ # Create a new instance.
7
+ def initialize
8
+ @root = ConfigurationGroup.new
9
+ @group_stack = [@root]
10
+ end
11
+
12
+ # Begin the definition of a group with the given name.
13
+ #
14
+ # @param [Symbol] name
15
+ # The name of the group.
16
+ def group(name)
17
+ new_group = @group_stack.last.ensure_child name
18
+ @group_stack.push new_group
19
+ yield
20
+ @group_stack.pop
21
+ end
22
+
23
+ # Set the value of the given key within the active group.
24
+ #
25
+ # @param [Symbol] key
26
+ # The key to set the value of within the active group.
27
+ # @param [Object] value
28
+ # The value to set the key to within the active group.
29
+ def set(key, value)
30
+ @group_stack.last.set_value(key, value)
31
+ end
32
+
33
+ # Returns the configuration value for the key
34
+ #
35
+ # @param [Symbol] key
36
+ def [](key)
37
+ @root[key]
38
+ end
39
+
40
+ # Load the specified file as an additional configuration file.
41
+ #
42
+ # == Usage
43
+ #
44
+ # Configuration files specify a hash of hashes in a more readable format.
45
+ # For example:
46
+ #
47
+ # group :example do
48
+ # set :one, 'foo'
49
+ # set :two, 'bar'
50
+ # end
51
+ #
52
+ # Internally creates a hash like:
53
+ #
54
+ # {:example => {:one => 'foo', :two => 'bar'}}
55
+ #
56
+ # A configuration file can overwrite the values specified by a preceding one
57
+ # without error. Groups can be opened and closed as desired and nesting
58
+ # groups is possible.
59
+ #
60
+ # @param [String] path
61
+ # The path of the configuration file.
62
+ def load(path)
63
+ instance_eval IO.read(path), path
64
+ end
65
+
66
+ # Yields the internal binding of the configuration to the given block.
67
+ #
68
+ # @param [Proc] block
69
+ # The block to yield the configuration's internal binding to.
70
+ def apply(&block)
71
+ @root.apply(block)
72
+ end
73
+
74
+ # Return the current state of the configuration.
75
+ def inspect
76
+ @root.inspect
77
+ end
78
+
79
+ private
80
+
81
+ # Class for controlling the creation and retrieval of configuration
82
+ # groups and values.
83
+ #
84
+ # Should not be used outside of this class.
85
+ class ConfigurationGroup # :nodoc:
86
+
87
+ # Create a new instance.
88
+ def initialize(*parents)
89
+ @parents = parents
90
+ @hash = {}
91
+ end
92
+
93
+ # Enables the fluent retrieval of groups within the hash.
94
+ def method_missing(sym, *args, &block)
95
+ raise missing_child sym unless @hash.key? sym
96
+ @hash[sym]
97
+ end
98
+
99
+ # Returns the configuration value for the key
100
+ #
101
+ # @param [Symbol] key
102
+ def [](key)
103
+ @hash[key]
104
+ end
105
+
106
+ # Ensures the hash contains a child hash for the specified key and
107
+ # returns it.
108
+ #
109
+ # @param [Symbol] key
110
+ # The key that must contain a child hash.
111
+ def ensure_child(key)
112
+ @hash[key] = ConfigurationGroup.new(@parents + [key]) unless @hash.key? key
113
+ @hash[key]
114
+ end
115
+
116
+ # Sets the value of the specified key.
117
+ #
118
+ # @param [Symbol] key
119
+ # The key to set the value of.
120
+ # @param [Object] value
121
+ # The value to set for the specified key.
122
+ def set_value(key, value)
123
+ @hash[key] = value
124
+ end
125
+
126
+ # Yields the internal binding of the configuration group to the given
127
+ # block.
128
+ #
129
+ # @param [Proc] block
130
+ # The block to yield the internal binding to.
131
+ def apply(block)
132
+ block.call(binding)
133
+ end
134
+
135
+ # Return the current state of the configuration.
136
+ def inspect
137
+ @hash.inspect
138
+ end
139
+
140
+ private
141
+
142
+ # Create a new error specifying that an attempt was made to retrieve a
143
+ # child that does not exist.
144
+ #
145
+ # @param [Symbol] sym
146
+ # The key of the requested child.
147
+ def missing_child(sym)
148
+ Bozo::ConfigurationError.new "#{@parents.any? ? @parents.join('.') : 'Root'} does not contain a value or group called '#{sym}' - known keys: #{@hash.keys.join(', ')}"
149
+ end
150
+
151
+ end
152
+
153
+ end
154
+
155
155
  end
@@ -1,54 +1,54 @@
1
- module Bozo::DependencyResolvers
2
-
3
- # Class for resolving dependencies using Bundler.
4
- class Bundler
5
-
6
- # Creates a new instance.
7
- def initialize
8
- @pre = false
9
- end
10
-
11
- # Ensures Bundler is installed and then calls installs the gems specified
12
- # in your Gemfile.
13
- def execute
14
- ensure_bundler_installed
15
- install_gems
16
- end
17
-
18
- # Decides whether when installing Bundler if the pre version of the gem
19
- # should be installed.
20
- #
21
- # @param [Boolean] pre
22
- # Whether the pre version of the Bundler gem should be installed.
23
- #
24
- # The pre version of Bundler will not be used unless explicitly
25
- # requested.
26
- #
27
- # Calling the method without any arguments will request that the pre
28
- # version should be used.
29
- def use_pre(pre = true)
30
- @pre = pre
31
- end
32
-
33
- private
34
-
35
- # Interrogates the list of installed gems and installs Bundler if it is
36
- # not found.
37
- def ensure_bundler_installed
38
- return if `gem list bundler`.include? 'bundler'
39
-
40
- args = %w{gem install --no-rdoc --no-ri bundler}
41
- args << '--pre' if @pre
42
-
43
- execute_command :rubygems, args
44
- end
45
-
46
- # Executes Bundler's install command, placing all of the installed gems
47
- # into the <tt>build/bundler</tt> directory.
48
- def install_gems
49
- execute_command :bundler, %w{bundle install --path build/bundler}
50
- end
51
-
52
- end
53
-
1
+ module Bozo::DependencyResolvers
2
+
3
+ # Class for resolving dependencies using Bundler.
4
+ class Bundler
5
+
6
+ # Creates a new instance.
7
+ def initialize
8
+ @pre = false
9
+ end
10
+
11
+ # Ensures Bundler is installed and then calls installs the gems specified
12
+ # in your Gemfile.
13
+ def execute
14
+ ensure_bundler_installed
15
+ install_gems
16
+ end
17
+
18
+ # Decides whether when installing Bundler if the pre version of the gem
19
+ # should be installed.
20
+ #
21
+ # @param [Boolean] pre
22
+ # Whether the pre version of the Bundler gem should be installed.
23
+ #
24
+ # The pre version of Bundler will not be used unless explicitly
25
+ # requested.
26
+ #
27
+ # Calling the method without any arguments will request that the pre
28
+ # version should be used.
29
+ def use_pre(pre = true)
30
+ @pre = pre
31
+ end
32
+
33
+ private
34
+
35
+ # Interrogates the list of installed gems and installs Bundler if it is
36
+ # not found.
37
+ def ensure_bundler_installed
38
+ return if `gem list bundler`.include? 'bundler'
39
+
40
+ args = %w{gem install --no-rdoc --no-ri bundler}
41
+ args << '--pre' if @pre
42
+
43
+ execute_command :rubygems, args
44
+ end
45
+
46
+ # Executes Bundler's install command, placing all of the installed gems
47
+ # into the <tt>build/bundler</tt> directory.
48
+ def install_gems
49
+ execute_command :bundler, %w{bundle install --path build/bundler}
50
+ end
51
+
52
+ end
53
+
54
54
  end
@@ -1,86 +1,86 @@
1
- module Bozo::DependencyResolvers
2
-
3
- # Class for resolving project dependencies using NuGet.
4
- class Nuget
5
-
6
- # Creates a new instance.
7
- def initialize
8
- @sources = []
9
- end
10
-
11
- # Add a URL that should be within the machine's configuration for
12
- # package resolution URLs.
13
- #
14
- # @param [String] url
15
- # A NuGet package resolving URL.
16
- def source(url)
17
- @sources << url
18
- end
19
-
20
- # Returns the build tools required for this dependency resolver to run
21
- # successfully.
22
- def required_tools
23
- :nuget
24
- end
25
-
26
- # Ensure all the specified sources are present and execute the dependency
27
- # resolver for all the files matching <tt>test/**/packages.config</tt> and
28
- # <tt>src/**/packages.config</tt> and <tt>packages.config</tt> if present.
29
- def execute
30
- add_package_sources
31
- install_packages 'test', '**', 'packages.config'
32
- install_packages 'src', '**', 'packages.config'
33
- install_packages 'packages.config'
34
- end
35
-
36
- private
37
-
38
- # Adds any sources that are required but are not mentioned by the
39
- # <tt>NuGet sources List</tt> command.
40
- def add_package_sources
41
- existing = `#{nuget_path} sources List` if @sources.any?
42
-
43
- @sources.select {|source| not existing.upcase.include? source.upcase}.each do |source|
44
- quoted_source = "\"#{source}\""
45
- log_debug "Missing nuget package source #{quoted_source}"
46
-
47
- args = []
48
-
49
- args << nuget_path
50
- args << 'sources'
51
- args << 'Add'
52
- args << '-Name'
53
- args << quoted_source
54
- args << '-Source'
55
- args << quoted_source
56
-
57
- log_debug "Adding nuget package source #{quoted_source}"
58
-
59
- execute_command :nuget, args
60
- end
61
- end
62
-
63
- def install_packages(*args)
64
- path_matcher = File.expand_path(File.join(args))
65
- Dir[path_matcher].each do |path|
66
- args = []
67
-
68
- args << nuget_path
69
- args << 'install'
70
- args << "\"#{path}\""
71
- args << '-OutputDirectory'
72
- args << "\"#{File.expand_path(File.join('packages'))}\""
73
-
74
- log_debug "Resolving nuget dependencies for #{path}"
75
-
76
- execute_command :nuget, args
77
- end
78
- end
79
-
80
- def nuget_path
81
- File.expand_path(File.join('build', 'tools', 'nuget', 'NuGet.exe'))
82
- end
83
-
84
- end
85
-
1
+ module Bozo::DependencyResolvers
2
+
3
+ # Class for resolving project dependencies using NuGet.
4
+ class Nuget
5
+
6
+ # Creates a new instance.
7
+ def initialize
8
+ @sources = []
9
+ end
10
+
11
+ # Add a URL that should be within the machine's configuration for
12
+ # package resolution URLs.
13
+ #
14
+ # @param [String] url
15
+ # A NuGet package resolving URL.
16
+ def source(url)
17
+ @sources << url
18
+ end
19
+
20
+ # Returns the build tools required for this dependency resolver to run
21
+ # successfully.
22
+ def required_tools
23
+ :nuget
24
+ end
25
+
26
+ # Ensure all the specified sources are present and execute the dependency
27
+ # resolver for all the files matching <tt>test/**/packages.config</tt> and
28
+ # <tt>src/**/packages.config</tt> and <tt>packages.config</tt> if present.
29
+ def execute
30
+ add_package_sources
31
+ install_packages 'test', '**', 'packages.config'
32
+ install_packages 'src', '**', 'packages.config'
33
+ install_packages 'packages.config'
34
+ end
35
+
36
+ private
37
+
38
+ # Adds any sources that are required but are not mentioned by the
39
+ # <tt>NuGet sources List</tt> command.
40
+ def add_package_sources
41
+ existing = `#{nuget_path} sources List` if @sources.any?
42
+
43
+ @sources.select {|source| not existing.upcase.include? source.upcase}.each do |source|
44
+ quoted_source = "\"#{source}\""
45
+ log_debug "Missing nuget package source #{quoted_source}"
46
+
47
+ args = []
48
+
49
+ args << nuget_path
50
+ args << 'sources'
51
+ args << 'Add'
52
+ args << '-Name'
53
+ args << quoted_source
54
+ args << '-Source'
55
+ args << quoted_source
56
+
57
+ log_debug "Adding nuget package source #{quoted_source}"
58
+
59
+ execute_command :nuget, args
60
+ end
61
+ end
62
+
63
+ def install_packages(*args)
64
+ path_matcher = File.expand_path(File.join(args))
65
+ Dir[path_matcher].each do |path|
66
+ args = []
67
+
68
+ args << nuget_path
69
+ args << 'install'
70
+ args << "\"#{path}\""
71
+ args << '-OutputDirectory'
72
+ args << "\"#{File.expand_path(File.join('packages'))}\""
73
+
74
+ log_debug "Resolving nuget dependencies for #{path}"
75
+
76
+ execute_command :nuget, args
77
+ end
78
+ end
79
+
80
+ def nuget_path
81
+ File.expand_path(File.join('build', 'tools', 'nuget', 'NuGet.exe'))
82
+ end
83
+
84
+ end
85
+
86
86
  end