markbates-gemtronics 0.0.1.20090812182507

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2009 markbates
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,3 @@
1
+ README
2
+ ========================================================================
3
+ gemtronics was developed by: markbates
data/bin/gemtronics ADDED
@@ -0,0 +1,100 @@
1
+ #!/opt/local/bin/ruby
2
+ command_message = %{
3
+ Available commands:
4
+ - install <group> <path> # Specify the group of gems to install. The default is 'default' You must all specify the path to the gemtronics file you wish to install from. The default is 'config/gemtronics.rb'
5
+ - generate <path> # Specify where you would like the gemtronics file generated. The default 'config/gemtronics.rb'
6
+ - convert <path> # Convert an existing Gemtools yml file to Gemtronics. The default is 'config/gems.yml'
7
+ }.strip
8
+
9
+ command = ARGV[0]
10
+ if command.nil?
11
+ puts %{
12
+ You MUST specify a command!
13
+
14
+ #{command_message}
15
+ }.strip
16
+ exit(-1)
17
+ end
18
+
19
+ require 'rubygems'
20
+ require 'gemtronics'
21
+ require 'fileutils'
22
+ require 'yaml'
23
+
24
+ case command
25
+ when 'install'
26
+ path = ARGV[2] || File.join('config', 'gemtronics.rb')
27
+ Gemtronics.load(path)
28
+ Gemtronics.install_gems(ARGV[1] || 'default')
29
+ when 'generate'
30
+ path = ARGV[1] || 'config'
31
+ FileUtils.mkdir_p(path)
32
+ File.open(File.join(path, 'gemtronics.rb'), 'w') do |f|
33
+ f.puts %{
34
+ group(:default) do |g|
35
+ # g.add('gem name here')
36
+ # g.add('gem name here', :version => '1.2.3')
37
+ # g.add('gem name here', :version => '1.2.3', :source => 'http://gems.example.com')
38
+ # g.add('gem name here', :version => '1.2.3', :source => 'http://gems.example.com', :require => ['file1', 'file2'])
39
+ end
40
+
41
+ group(:production, :dependencies => :default) do |g|
42
+
43
+ end
44
+
45
+ group(:development, :dependencies => :default) do |g|
46
+
47
+ end
48
+
49
+ group(:test, :dependencies => :development) do |g|
50
+
51
+ end
52
+ }.strip
53
+ end
54
+ when 'convert'
55
+ path = ARGV[1] || File.join('config', 'gems.yml')
56
+ path = File.join(path, 'gems.yml') unless path.match(/gems.yml$/)
57
+ gem_list = YAML.load(File.read(path))
58
+ top_options = {}
59
+ gems = []
60
+ gem_list.each do |key, value|
61
+ if key == 'gems'
62
+ gems = value
63
+ else
64
+ top_options[key.to_sym] = value
65
+ end
66
+ end
67
+
68
+ out_path = path.gsub('gems.yml', 'gemtronics.rb')
69
+ File.open(out_path, 'w') do |f|
70
+ unless top_options.empty?
71
+ f.puts "group(:default, #{top_options.inspect.gsub('=>', ' => ')}) do |g|"
72
+ else
73
+ f.puts "group(:default) do |g|"
74
+ end
75
+
76
+ gems.each do |gemdef|
77
+ x = " g.add('#{gemdef['name']}'"
78
+ options = {}
79
+ options[:require] = gemdef['require_name'] if gemdef['require_name']
80
+ options[:version] = gemdef['version'] if gemdef['version']
81
+ options[:load] = false if gemdef['load'] == false
82
+ unless options.empty?
83
+ x << ", #{options.inspect.gsub('=>', ' => ')})"
84
+ else
85
+ x << ')'
86
+ end
87
+ f.puts x
88
+ end
89
+
90
+ f.puts 'end'
91
+ end
92
+ puts File.read(out_path)
93
+ else
94
+ puts %{
95
+ You entered an UNKNOWN command '#{command}'!
96
+
97
+ #{command_message}
98
+ }.strip
99
+ exit(-1)
100
+ end
@@ -0,0 +1,11 @@
1
+ module Gemtronics
2
+
3
+ class << self
4
+
5
+ def method_missing(sym, *args)
6
+ Gemtronics::Manager.instance.send(sym, *args)
7
+ end
8
+
9
+ end
10
+
11
+ end # Gemtronics
@@ -0,0 +1,42 @@
1
+ module Gemtronics
2
+ class Grouper
3
+ attr_accessor :gems
4
+ attr_accessor :group_options
5
+
6
+ def initialize(options = {})
7
+ self.gems = []
8
+ deps = options.delete(:dependencies)
9
+ if deps
10
+ [deps].flatten.each do |dep|
11
+ self.dependency(dep)
12
+ end
13
+ end
14
+ self.group_options = options
15
+ self
16
+ end
17
+
18
+ def add(name, options = {})
19
+ g = Gemtronics::Manager::GLOBAL_DEFAULT_OPTIONS.merge(self.group_options.merge({:name => name.to_s, :require => [name.to_s]}.merge(options)))
20
+ g[:require] = [g[:require]].flatten
21
+ self.gems << g
22
+ end
23
+
24
+ def remove(name)
25
+ self.gems.each do |g|
26
+ if g[:name] = name.to_s
27
+ self.gems.delete(g)
28
+ break
29
+ end
30
+ end
31
+ end
32
+
33
+ def dependency(name)
34
+ group = Gemtronics::Manager.instance.groups[name.to_sym]
35
+ if group
36
+ self.gems << group.gems.dup
37
+ self.gems.flatten!
38
+ end
39
+ end
40
+
41
+ end # Grouper
42
+ end # Gemtronics
@@ -0,0 +1,79 @@
1
+ module Gemtronics
2
+ class Manager
3
+ include Singleton
4
+
5
+ GLOBAL_DEFAULT_OPTIONS = {:load => true, :version => '>=0.0.0', :source => 'http://gems.rubyforge.org'}
6
+
7
+ attr_accessor :groups
8
+
9
+ def initialize
10
+ reset!
11
+ end
12
+
13
+ def group(name, options = {})
14
+ name = name.to_sym
15
+ options = GLOBAL_DEFAULT_OPTIONS.merge(options)
16
+ g = (self.groups[name] ||= Gemtronics::Grouper.new(options))
17
+ yield g if block_given?
18
+ end
19
+
20
+ def alias_group(name, src)
21
+ group(name, :dependencies => src)
22
+ end
23
+
24
+ def load(file = File.join(FileUtils.pwd, 'config', 'gemtronics.rb'))
25
+ eval(File.read(file), binding)
26
+ end
27
+
28
+ def require_gems(group = :default, options = {})
29
+ group = self.groups[group.to_sym]
30
+ return if group.nil?
31
+ options = {:verbose => false}.merge(options)
32
+ group.gems.each do |g|
33
+ if g[:load] == true
34
+ gem(g[:name], g[:version])
35
+ g[:require].each do |f|
36
+ puts "require #{f}" if options[:verbose]
37
+ require f
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def install_gems(group = :default)
44
+ group = self.groups[group.to_sym]
45
+ return if group.nil?
46
+
47
+ group.gems.each do |g|
48
+ unless gem_installed?(g[:name], g[:version])
49
+ cmd = "gem install #{g[:name]} --source=#{g[:source]}"
50
+ unless g[:version].match(/^(\>\=|\>)/)
51
+ cmd << " --version=#{g[:version]}"
52
+ end
53
+ system cmd
54
+ end
55
+ end
56
+ end
57
+
58
+ def install_all_gems
59
+ self.groups.each do |name, value|
60
+ self.install_gems(name)
61
+ end
62
+ end
63
+
64
+ def reset!
65
+ self.groups = {}
66
+ end
67
+
68
+ def gem_installed?(name, version)
69
+ begin
70
+ gem(name, version)
71
+ return true
72
+ rescue Gem::LoadError => e
73
+ return true if e.message.match(/can't activate/)
74
+ return false
75
+ end
76
+ end
77
+
78
+ end # Manager
79
+ end # Gemtronics
data/lib/gemtronics.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'singleton'
2
+ Dir.glob(File.join(File.dirname(__FILE__), 'gemtronics', '**/*.rb')).each do |f|
3
+ require File.expand_path(f)
4
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markbates-gemtronics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.20090812182507
5
+ platform: ruby
6
+ authors:
7
+ - markbates
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-12 00:00:00 -07:00
13
+ default_executable: gemtronics
14
+ dependencies: []
15
+
16
+ description: "gemtronics was developed by: markbates"
17
+ email: ""
18
+ executables:
19
+ - gemtronics
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - LICENSE
25
+ files:
26
+ - lib/gemtronics/gemtronics.rb
27
+ - lib/gemtronics/grouper.rb
28
+ - lib/gemtronics/manager.rb
29
+ - lib/gemtronics.rb
30
+ - README
31
+ - LICENSE
32
+ - bin/gemtronics
33
+ has_rdoc: false
34
+ homepage: ""
35
+ licenses:
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project: magrathea
56
+ rubygems_version: 1.3.5
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: gemtronics
60
+ test_files: []
61
+