ruby-config 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ == 0.0.1 / 2008-11-09
2
+
3
+ * 0.0.1 First release
4
+ * Simple user interface for user-choices
5
+ * Some tests, it's very simple. Just to insure user-choices works
@@ -0,0 +1,8 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/ruby-config.rb
6
+ test/test_commandline_source.rb
7
+ test/test_helper.rb
8
+ test/test_ruby-config.rb
@@ -0,0 +1,60 @@
1
+ = ruby-config
2
+ by Leon Bogaert
3
+ http://www.vanutsteen.nl
4
+
5
+ == DESCRIPTION:
6
+
7
+ A different interface for the user-choices gem. The config can now be instantiated as an object and supports sub-configs and can be build from different files. The advantage is that you can ruby-config in a kinda plugin structure.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * No know problems. If you find one: please send it to me
12
+
13
+ == SYNOPSIS:
14
+
15
+ conf = RubyConfig.new
16
+ conf.add_source(UserChoices::CommandLineSource, :usage, 'Usage description')
17
+ conf.add_option(:ssh, :type=>:boolean) { | command_line |
18
+ command_line.uses_switch("-s", "--ssh",
19
+ "Use ssh to open connection.")
20
+ }
21
+ conf.build
22
+ p conf.ssh
23
+
24
+ For more examples, see: http://user-choices.rubyforge.org
25
+
26
+ There are a few minor changes. For example: user-choices uses add_choice while ruby-config uses add_option
27
+
28
+ == REQUIREMENTS:
29
+
30
+ * user-choices gem
31
+ * _why's metaid gems
32
+
33
+ == INSTALL:
34
+
35
+ * gem install ruby-config
36
+
37
+ == LICENSE:
38
+
39
+ (The MIT License)
40
+
41
+ Copyright (c) 2008 FIXME (different license?)
42
+
43
+ Permission is hereby granted, free of charge, to any person obtaining
44
+ a copy of this software and associated documentation files (the
45
+ 'Software'), to deal in the Software without restriction, including
46
+ without limitation the rights to use, copy, modify, merge, publish,
47
+ distribute, sublicense, and/or sell copies of the Software, and to
48
+ permit persons to whom the Software is furnished to do so, subject to
49
+ the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be
52
+ included in all copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
55
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
57
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
58
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
59
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
60
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # Look in the tasks/setup.rb file for the various options that can be
2
+ # configured in this Rakefile. The .rake files in the tasks directory
3
+ # are where the options are used.
4
+
5
+ begin
6
+ require 'bones'
7
+ Bones.setup
8
+ rescue LoadError
9
+ load 'tasks/setup.rb'
10
+ end
11
+
12
+ ensure_in_path 'lib'
13
+ require 'ruby-config'
14
+
15
+ task :default => 'spec:run'
16
+
17
+ Object.send(:remove_const, :SUDO) if defined? SUDO
18
+ Object.send(:remove_const, :HAVE_GIT) if defined? HAVE_GIT
19
+ SUDO = ''
20
+ HAVE_GIT = true
21
+
22
+ PROJ.name = 'ruby-config'
23
+ PROJ.authors = 'Leon Bogaert'
24
+ PROJ.email = 'leon@tim-online.nl'
25
+ PROJ.url = 'www.vanutsteen.nl'
26
+ PROJ.version = RubyConfig::VERSION
27
+ PROJ.rubyforge.name = 'ruby-config'
28
+ PROJ.exclude = %w(.git pkg/ nbproject/ doc/ website/ )
29
+ PROJ.gem.dependencies << 'metaid'
30
+ PROJ.gem.dependencies << 'user-choices'
31
+
32
+ #PROJ.rdoc.remote_dir = 'docs/'
33
+ PROJ.rcov.opts << "--exclude rcov.rb"
34
+
35
+ PROJ.spec.opts << '--color'
36
+
37
+ # EOF
@@ -0,0 +1,109 @@
1
+ require 'rubygems'
2
+ require 'user-choices'
3
+ require 'metaid'
4
+
5
+ unless defined? RubyConfig
6
+
7
+ class RubyConfig
8
+ VERSION = '0.0.1'
9
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
10
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
11
+
12
+ def self.version
13
+ VERSION
14
+ end
15
+
16
+ def self.libpath( *args )
17
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
18
+ end
19
+
20
+ def self.path( *args )
21
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
22
+ end
23
+
24
+ #Adds a method to the RubyConfig object which is another RubyConfig object
25
+ #This way you can add subconfigs (plugins?) to a base config
26
+ def add_subconfig(config_name)
27
+ define_config_methods(config_name)
28
+ self.send("#{config_name}=", RubyConfig.new)
29
+ end
30
+
31
+ #UserChoice methods:
32
+
33
+ #see: http://user-choices.rubyforge.org/rdoc/classes/UserChoices/ChoicesBuilder.html#M000003
34
+ def add_source(*args)
35
+ self.builder.add_source(*args)
36
+ end
37
+
38
+ #Original the add_choice method from user-choice
39
+ def add_option(*args, &block)
40
+ self.options << args.first
41
+ self.builder.add_choice(*args, &block)
42
+ end
43
+
44
+ #Get the yaml, parameter, etc. parameters and put them in conf-methodss
45
+ def build
46
+ builder_values = builder.build
47
+ self.use_values(builder_values)
48
+ end
49
+
50
+ protected
51
+ def builder
52
+ RubyConfig.builder
53
+ end
54
+
55
+ def configs
56
+ @configs ||= {}
57
+ end
58
+
59
+ def options
60
+ @options ||= []
61
+ end
62
+
63
+ def use_values(builder_values)
64
+ self.options.each do |option|
65
+ value = builder_values[option]
66
+ builder_values.delete(option)
67
+
68
+ define_value_methods(option)
69
+ self.send("#{option}=", value)
70
+ end
71
+
72
+ self.configs.each do |name, config|
73
+ config.use_values(builder_values)
74
+ end
75
+
76
+ end
77
+
78
+ private
79
+ def self.builder
80
+ @builder ||= UserChoices::ChoicesBuilder.new
81
+ end
82
+
83
+ def values
84
+ @values ||= {}
85
+ end
86
+
87
+ def define_config_methods(config_name)
88
+ config_name.to_s.downcase!
89
+
90
+ self.meta_def(config_name) do
91
+ configs[config_name]
92
+ end
93
+
94
+ self.meta_def("#{config_name}=") do |value|
95
+ configs[config_name] = value
96
+ end
97
+ end
98
+
99
+ def define_value_methods(value_name)
100
+ self.meta_def(value_name) do
101
+ values[value_name]
102
+ end
103
+
104
+ self.meta_def("#{value_name}=") do |value|
105
+ values[value_name] = value
106
+ end
107
+ end
108
+ end #RubyConfig
109
+ end #defined?
@@ -0,0 +1,80 @@
1
+
2
+ begin
3
+ require 'bones/smtp_tls'
4
+ rescue LoadError
5
+ require 'net/smtp'
6
+ end
7
+ require 'time'
8
+
9
+ namespace :ann do
10
+
11
+ # A prerequisites task that all other tasks depend upon
12
+ task :prereqs
13
+
14
+ file PROJ.ann.file do
15
+ ann = PROJ.ann
16
+ puts "Generating #{ann.file}"
17
+ File.open(ann.file,'w') do |fd|
18
+ fd.puts("#{PROJ.name} version #{PROJ.version}")
19
+ fd.puts(" by #{Array(PROJ.authors).first}") if PROJ.authors
20
+ fd.puts(" #{PROJ.url}") if PROJ.url.valid?
21
+ fd.puts(" (the \"#{PROJ.release_name}\" release)") if PROJ.release_name
22
+ fd.puts
23
+ fd.puts("== DESCRIPTION")
24
+ fd.puts
25
+ fd.puts(PROJ.description)
26
+ fd.puts
27
+ fd.puts(PROJ.changes.sub(%r/^.*$/, '== CHANGES'))
28
+ fd.puts
29
+ ann.paragraphs.each do |p|
30
+ fd.puts "== #{p.upcase}"
31
+ fd.puts
32
+ fd.puts paragraphs_of(PROJ.readme_file, p).join("\n\n")
33
+ fd.puts
34
+ end
35
+ fd.puts ann.text if ann.text
36
+ end
37
+ end
38
+
39
+ desc "Create an announcement file"
40
+ task :announcement => ['ann:prereqs', PROJ.ann.file]
41
+
42
+ desc "Send an email announcement"
43
+ task :email => ['ann:prereqs', PROJ.ann.file] do
44
+ ann = PROJ.ann
45
+ from = ann.email[:from] || PROJ.email
46
+ to = Array(ann.email[:to])
47
+
48
+ ### build a mail header for RFC 822
49
+ rfc822msg = "From: #{from}\n"
50
+ rfc822msg << "To: #{to.join(',')}\n"
51
+ rfc822msg << "Subject: [ANN] #{PROJ.name} #{PROJ.version}"
52
+ rfc822msg << " (#{PROJ.release_name})" if PROJ.release_name
53
+ rfc822msg << "\n"
54
+ rfc822msg << "Date: #{Time.new.rfc822}\n"
55
+ rfc822msg << "Message-Id: "
56
+ rfc822msg << "<#{"%.8f" % Time.now.to_f}@#{ann.email[:domain]}>\n\n"
57
+ rfc822msg << File.read(ann.file)
58
+
59
+ params = [:server, :port, :domain, :acct, :passwd, :authtype].map do |key|
60
+ ann.email[key]
61
+ end
62
+
63
+ params[3] = PROJ.email if params[3].nil?
64
+
65
+ if params[4].nil?
66
+ STDOUT.write "Please enter your e-mail password (#{params[3]}): "
67
+ params[4] = STDIN.gets.chomp
68
+ end
69
+
70
+ ### send email
71
+ Net::SMTP.start(*params) {|smtp| smtp.sendmail(rfc822msg, from, to)}
72
+ end
73
+ end # namespace :ann
74
+
75
+ desc 'Alias to ann:announcement'
76
+ task :ann => 'ann:announcement'
77
+
78
+ CLOBBER << PROJ.ann.file
79
+
80
+ # EOF
@@ -0,0 +1,20 @@
1
+
2
+ if HAVE_BONES
3
+
4
+ namespace :bones do
5
+
6
+ desc 'Show the PROJ open struct'
7
+ task :debug do |t|
8
+ atr = if t.application.top_level_tasks.length == 2
9
+ t.application.top_level_tasks.pop
10
+ end
11
+
12
+ if atr then Bones::Debug.show_attr(PROJ, atr)
13
+ else Bones::Debug.show PROJ end
14
+ end
15
+
16
+ end # namespace :bones
17
+
18
+ end # HAVE_BONES
19
+
20
+ # EOF
@@ -0,0 +1,192 @@
1
+
2
+ require 'find'
3
+ require 'rake/packagetask'
4
+ require 'rubygems/user_interaction'
5
+ require 'rubygems/builder'
6
+
7
+ module Bones
8
+ class GemPackageTask < Rake::PackageTask
9
+ # Ruby GEM spec containing the metadata for this package. The
10
+ # name, version and package_files are automatically determined
11
+ # from the GEM spec and don't need to be explicitly provided.
12
+ #
13
+ attr_accessor :gem_spec
14
+
15
+ # Tasks from the Bones gem directory
16
+ attr_reader :bones_files
17
+
18
+ # Create a GEM Package task library. Automatically define the gem
19
+ # if a block is given. If no block is supplied, then +define+
20
+ # needs to be called to define the task.
21
+ #
22
+ def initialize(gem_spec)
23
+ init(gem_spec)
24
+ yield self if block_given?
25
+ define if block_given?
26
+ end
27
+
28
+ # Initialization tasks without the "yield self" or define
29
+ # operations.
30
+ #
31
+ def init(gem)
32
+ super(gem.name, gem.version)
33
+ @gem_spec = gem
34
+ @package_files += gem_spec.files if gem_spec.files
35
+ @bones_files = []
36
+
37
+ local_setup = File.join(Dir.pwd, %w[tasks setup.rb])
38
+ if !test(?e, local_setup)
39
+ Dir.glob(::Bones.path(%w[lib bones tasks *])).each {|fn| bones_files << fn}
40
+ gem_spec.files = (gem_spec.files +
41
+ bones_files.map {|fn| File.join('tasks', File.basename(fn))}).sort
42
+ end
43
+ end
44
+
45
+ # Create the Rake tasks and actions specified by this
46
+ # GemPackageTask. (+define+ is automatically called if a block is
47
+ # given to +new+).
48
+ #
49
+ def define
50
+ super
51
+ task :prereqs
52
+ task :package => ['gem:prereqs', "#{package_dir_path}/#{gem_file}"]
53
+ file "#{package_dir_path}/#{gem_file}" => [package_dir_path] + package_files + bones_files do
54
+ when_writing("Creating GEM") {
55
+ chdir(package_dir_path) do
56
+ Gem::Builder.new(gem_spec).build
57
+ verbose(true) {
58
+ mv gem_file, "../#{gem_file}"
59
+ }
60
+ end
61
+ }
62
+ end
63
+
64
+ file package_dir_path => bones_files do
65
+ mkdir_p package_dir rescue nil
66
+ bones_files.each do |fn|
67
+ base_fn = File.join('tasks', File.basename(fn))
68
+ f = File.join(package_dir_path, base_fn)
69
+ fdir = File.dirname(f)
70
+ mkdir_p(fdir) if !File.exist?(fdir)
71
+ if File.directory?(fn)
72
+ mkdir_p(f)
73
+ else
74
+ raise "file name conflict for '#{base_fn}' (conflicts with '#{fn}')" if test(?e, f)
75
+ safe_ln(fn, f)
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ def gem_file
82
+ if @gem_spec.platform == Gem::Platform::RUBY
83
+ "#{package_name}.gem"
84
+ else
85
+ "#{package_name}-#{@gem_spec.platform}.gem"
86
+ end
87
+ end
88
+ end # class GemPackageTask
89
+ end # module Bones
90
+
91
+ namespace :gem do
92
+
93
+ PROJ.gem._spec = Gem::Specification.new do |s|
94
+ s.name = PROJ.name
95
+ s.version = PROJ.version
96
+ s.summary = PROJ.summary
97
+ s.authors = Array(PROJ.authors)
98
+ s.email = PROJ.email
99
+ s.homepage = Array(PROJ.url).first
100
+ s.rubyforge_project = PROJ.rubyforge.name
101
+
102
+ s.description = PROJ.description
103
+
104
+ PROJ.gem.dependencies.each do |dep|
105
+ s.add_dependency(*dep)
106
+ end
107
+
108
+ PROJ.gem.development_dependencies.each do |dep|
109
+ s.add_development_dependency(*dep)
110
+ end
111
+
112
+ s.files = PROJ.gem.files
113
+ s.executables = PROJ.gem.executables.map {|fn| File.basename(fn)}
114
+ s.extensions = PROJ.gem.files.grep %r/extconf\.rb$/
115
+
116
+ s.bindir = 'bin'
117
+ dirs = Dir["{#{PROJ.libs.join(',')}}"]
118
+ s.require_paths = dirs unless dirs.empty?
119
+
120
+ incl = Regexp.new(PROJ.rdoc.include.join('|'))
121
+ excl = PROJ.rdoc.exclude.dup.concat %w[\.rb$ ^(\.\/|\/)?ext]
122
+ excl = Regexp.new(excl.join('|'))
123
+ rdoc_files = PROJ.gem.files.find_all do |fn|
124
+ case fn
125
+ when excl; false
126
+ when incl; true
127
+ else false end
128
+ end
129
+ s.rdoc_options = PROJ.rdoc.opts + ['--main', PROJ.rdoc.main]
130
+ s.extra_rdoc_files = rdoc_files
131
+ s.has_rdoc = true
132
+
133
+ if test ?f, PROJ.test.file
134
+ s.test_file = PROJ.test.file
135
+ else
136
+ s.test_files = PROJ.test.files.to_a
137
+ end
138
+
139
+ # Do any extra stuff the user wants
140
+ PROJ.gem.extras.each do |msg, val|
141
+ case val
142
+ when Proc
143
+ val.call(s.send(msg))
144
+ else
145
+ s.send "#{msg}=", val
146
+ end
147
+ end
148
+ end # Gem::Specification.new
149
+
150
+ Bones::GemPackageTask.new(PROJ.gem._spec) do |pkg|
151
+ pkg.need_tar = PROJ.gem.need_tar
152
+ pkg.need_zip = PROJ.gem.need_zip
153
+ end
154
+
155
+ desc 'Show information about the gem'
156
+ task :debug => 'gem:prereqs' do
157
+ puts PROJ.gem._spec.to_ruby
158
+ end
159
+
160
+ desc 'Install the gem'
161
+ task :install => [:clobber, 'gem:package'] do
162
+ sh "#{SUDO} #{GEM} install --local pkg/#{PROJ.gem._spec.full_name}"
163
+
164
+ # use this version of the command for rubygems > 1.0.0
165
+ #sh "#{SUDO} #{GEM} install --no-update-sources pkg/#{PROJ.gem._spec.full_name}"
166
+ end
167
+
168
+ desc 'Uninstall the gem'
169
+ task :uninstall do
170
+ installed_list = Gem.source_index.find_name(PROJ.name)
171
+ if installed_list and installed_list.collect { |s| s.version.to_s}.include?(PROJ.version) then
172
+ sh "#{SUDO} #{GEM} uninstall --version '#{PROJ.version}' --ignore-dependencies --executables #{PROJ.name}"
173
+ end
174
+ end
175
+
176
+ desc 'Reinstall the gem'
177
+ task :reinstall => [:uninstall, :install]
178
+
179
+ desc 'Cleanup the gem'
180
+ task :cleanup do
181
+ sh "#{SUDO} #{GEM} cleanup #{PROJ.gem._spec.name}"
182
+ end
183
+ end # namespace :gem
184
+
185
+
186
+ desc 'Alias to gem:package'
187
+ task :gem => 'gem:package'
188
+
189
+ task :clobber => 'gem:clobber_package'
190
+ remove_desc_for_task 'gem:clobber_package'
191
+
192
+ # EOF