simonmenke-gm 0.0.1

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/README.textile ADDED
@@ -0,0 +1,43 @@
1
+ h1. GM (gem make)
2
+
3
+ GM is a gem and gemspec builder for use with github.
4
+
5
+
6
+ h2. Configuration
7
+
8
+ ~/.gmrc.yml
9
+
10
+ author:
11
+ name: [your name]
12
+ email: [your email adres]
13
+ github:
14
+ username: [your github username]
15
+
16
+ paths/to/gem/gmfile.yml
17
+
18
+ general:
19
+ name: [name of the gem]
20
+ version: [version]
21
+ summary: [a short description]
22
+ dependencies:
23
+ - gem-name version-requirement
24
+ - gem2-name version-requirement
25
+
26
+ h2. Example
27
+
28
+ ~/.gmrc.yml
29
+
30
+ author:
31
+ name: Simon Menke
32
+ email: simon.menke@gmail.com
33
+ github:
34
+ username: simonmenke
35
+
36
+ paths/to/gem/gmfile.yml
37
+
38
+ general:
39
+ name: gm
40
+ version: 0.0.1
41
+ summary: Build gems with ease.
42
+ dependencies:
43
+ - configatron >= 2.2.1
data/bin/gm ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__)+'/../lib/gm'
4
+
5
+ GM::App.instance.run
data/lib/gm.rb ADDED
@@ -0,0 +1,12 @@
1
+
2
+ begin
3
+ require 'configatron'
4
+ rescue LoadError
5
+ retry if require 'rubygems'
6
+ end
7
+
8
+ module GM
9
+ end
10
+
11
+ require File.dirname(__FILE__)+'/gm/app'
12
+ require File.dirname(__FILE__)+'/gm/configuration_pass'
data/lib/gm/app.rb ADDED
@@ -0,0 +1,108 @@
1
+ require 'singleton'
2
+
3
+ module GM
4
+
5
+ class App
6
+ include Singleton
7
+
8
+ COMMANDS = %w( help build spec install clean )
9
+
10
+ def parse_options
11
+ @command = ARGV.shift unless ARGV.empty?
12
+ @command = nil unless COMMANDS.include? @command
13
+ @command = 'help' if @command.nil?
14
+ end
15
+
16
+ def run
17
+ load_passes
18
+ parse_options
19
+ send "run_#{@command}"
20
+ end
21
+
22
+ def run_help
23
+ puts "#{File.basename($0)} #{COMMANDS.join('|')}"
24
+ end
25
+
26
+ def run_spec
27
+ build_gemspec
28
+ write_spec_file
29
+ end
30
+
31
+ def run_build
32
+ @emulate = true
33
+ build_gemspec
34
+ build_spec
35
+ end
36
+
37
+ def run_install
38
+ @emulate = true
39
+ build_gemspec
40
+ build_spec
41
+ install_gem
42
+ end
43
+
44
+ def run_clean
45
+ system("rm -rf pkg/* *.gemspec")
46
+ end
47
+
48
+ def self.emulate?
49
+ instance.emulate?
50
+ end
51
+
52
+ def emulate?
53
+ @emulate || false
54
+ end
55
+
56
+ private
57
+
58
+ def load_passes
59
+ Dir.glob(File.dirname(__FILE__)+'/../passes/*.rb') do |path|
60
+ require path
61
+ end
62
+ end
63
+
64
+ def install_gem
65
+ system("sudo gem install pkg/#{@gem_file_name}")
66
+ end
67
+
68
+ def build_spec
69
+ builder = Gem::Builder.new @spec
70
+ @gem_file_name = builder.build
71
+ system("rm -f pkg/#{@gem_file_name}")
72
+ system("mkdir -p pkg && mv #{@gem_file_name} pkg/")
73
+ end
74
+
75
+ def write_spec_file
76
+ File.open("#{@spec.name}.gemspec", 'w+') do |f|
77
+ f.write @spec.to_ruby
78
+ end
79
+ end
80
+
81
+ def build_gemspec
82
+ @spec = Gem::Specification.new do |s|
83
+ ConfigurationPassQueue.new(:init).run(s)
84
+ ConfigurationPassQueue.new(:pre).run(s)
85
+ ConfigurationPassQueue.new(:normal).run(s)
86
+ ConfigurationPassQueue.new(:post).run(s)
87
+ end
88
+ @spec.validate
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+
95
+ module Gem
96
+
97
+ class Specification
98
+
99
+ alias_method :ruby_code_old, :ruby_code
100
+
101
+ def ruby_code(obj)
102
+ obj = nil if obj.is_a? Configatron::Store
103
+ ruby_code_old(obj)
104
+ end
105
+
106
+ end
107
+
108
+ end
@@ -0,0 +1,79 @@
1
+
2
+ module GM
3
+
4
+ class << self
5
+ attr_accessor :configuration_passes
6
+ end
7
+ self.configuration_passes = Hash.new { |h, k| h[k] = {} }
8
+
9
+ def self.exclude_pass(name, fase=:normal)
10
+ self.configuration_passes[fase.to_sym].delete(name.to_sym)
11
+ end
12
+
13
+ module DSL
14
+ def init_pass(name, dependencies=[], &proc)
15
+ ConfigurationPass.new(name, dependencies, &proc).register(:init)
16
+ end
17
+ def pre_pass(name, dependencies=[], &proc)
18
+ ConfigurationPass.new(name, dependencies, &proc).register(:pre)
19
+ end
20
+ def pass(name, dependencies=[], &proc)
21
+ ConfigurationPass.new(name, dependencies, &proc).register(:normal)
22
+ end
23
+ def post_pass(name, dependencies=[], &proc)
24
+ ConfigurationPass.new(name, dependencies, &proc).register(:post)
25
+ end
26
+ end
27
+
28
+ class ConfigurationPassQueue
29
+ attr_accessor :queue
30
+ attr_accessor :passes
31
+ attr_accessor :processed_passes
32
+
33
+ def initialize(fase)
34
+ @passes = GM.configuration_passes[fase.to_sym].dup
35
+ @processed_passes = []
36
+ @queue = @passes.values
37
+ end
38
+
39
+ def run(spec)
40
+ until @queue.empty?
41
+ @queue.each do |pass|
42
+ if run_pass(pass, spec)
43
+ @queue.delete(pass)
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ def run_pass(pass, spec)
50
+ return false unless (pass.dependencies - @processed_passes).empty?
51
+ pass.run spec
52
+ @processed_passes << pass.name
53
+ return true
54
+ end
55
+ end
56
+
57
+ class ConfigurationPass
58
+
59
+ attr_accessor :proc
60
+ attr_accessor :name
61
+ attr_accessor :dependencies
62
+
63
+ def initialize(name, dependencies=[], &proc)
64
+ @name = name.to_sym
65
+ @dependencies = [dependencies].flatten.collect { |dep| dep.to_sym }
66
+ @proc = proc || Proc.new { |spec| }
67
+ end
68
+
69
+ def register(fase)
70
+ GM.configuration_passes[fase.to_sym][@name] = self
71
+ end
72
+
73
+ def run(spec)
74
+ @proc.call spec
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,78 @@
1
+ include GM::DSL
2
+
3
+ pre_pass :configatron_defaults do |spec|
4
+
5
+ configatron.configure_from_hash({
6
+ :general => {
7
+ :name => nil,
8
+ :version => nil,
9
+ :summary => nil,
10
+ :homepage => nil
11
+ },
12
+ :dependencies => [],
13
+
14
+ :author => {
15
+ :name => nil,
16
+ :email => nil
17
+ },
18
+
19
+ :github => {
20
+ :project => nil,
21
+ :username => nil
22
+ },
23
+
24
+ :rubyforge => {
25
+ :project => nil
26
+ },
27
+
28
+ :excluded_passes => []
29
+ })
30
+
31
+ end
32
+
33
+ pre_pass :configatron_global, :configatron_defaults do |s|
34
+ c = configatron
35
+ c.configure_from_yaml(File.expand_path('~/.gmrc.yml'))
36
+ end
37
+
38
+ pre_pass :configatron_local, :configatron_global do |s|
39
+ c = configatron
40
+ c.configure_from_yaml(File.expand_path('gmfile.yml'))
41
+ end
42
+
43
+ pre_pass :configatron_normalize, :configatron_local do |s|
44
+ c = configatron
45
+
46
+ if c.rubyforge.project.nil?
47
+ c.rubyforge.project = c.general.name
48
+ end
49
+
50
+ if c.github.project.nil?
51
+ c.github.project = c.general.name
52
+ end
53
+ end
54
+
55
+ pre_pass :configatron_exclude_passes, :configatron_local do |s|
56
+ c = configatron
57
+ c.excluded_passes.each do |pass|
58
+ GM.exclude_pass(pass)
59
+ end
60
+ end
61
+
62
+ pass :configatron do |s|
63
+ c = configatron
64
+ s.name = c.general.name
65
+ s.version = c.general.version
66
+ s.summary = c.general.summary
67
+ s.homepage = c.general.homepage
68
+
69
+ s.author = c.author.name
70
+ s.email = c.author.email
71
+
72
+ s.rubyforge_project = c.rubyforge.project
73
+
74
+ c.dependencies.each do |dependency|
75
+ gem, requirement = dependency.strip.split(/\s+/, 2)
76
+ s.add_dependency gem.strip, requirement.strip
77
+ end
78
+ end
@@ -0,0 +1,8 @@
1
+ include GM::DSL
2
+
3
+ init_pass :defaults do |spec|
4
+
5
+ spec.platform = Gem::Platform::RUBY
6
+ spec.files = []
7
+
8
+ end
@@ -0,0 +1,10 @@
1
+ include GM::DSL
2
+
3
+ pass :executables do |spec|
4
+
5
+ paths = Dir.glob('bin/*')
6
+ spec.executables = paths.collect do |path|
7
+ File.basename(path)
8
+ end
9
+
10
+ end
@@ -0,0 +1,15 @@
1
+ include GM::DSL
2
+
3
+ pass :files do |spec|
4
+
5
+ files = []
6
+ files += Dir.glob('bin/*')
7
+ files += Dir.glob('lib/**/*.rb')
8
+ files += Dir.glob('*.{txt,rdoc,textile}')
9
+ spec.files += files
10
+
11
+ end
12
+
13
+ pass :require_paths do |spec|
14
+ spec.require_paths = ['lib']
15
+ end
@@ -0,0 +1,9 @@
1
+ include GM::DSL
2
+
3
+ post_pass :emulate_github do |spec|
4
+
5
+ if GM::App.emulate?
6
+ spec.name = "#{configatron.github.username}-#{configatron.github.project}"
7
+ end
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+ include GM::DSL
2
+
3
+ pass :rails do |spec|
4
+
5
+ spec.files += Dir.glob('rails/init.rb')
6
+
7
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simonmenke-gm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Simon Menke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-12 00:00:00 -08:00
13
+ default_executable: gm
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: configatron
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.2.1
23
+ version:
24
+ description:
25
+ email: simon.menke@gmail.com
26
+ executables:
27
+ - gm
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - bin/gm
34
+ - lib/gm/app.rb
35
+ - lib/gm/configuration_pass.rb
36
+ - lib/gm.rb
37
+ - lib/passes/configatron.rb
38
+ - lib/passes/defaults.rb
39
+ - lib/passes/executables.rb
40
+ - lib/passes/files.rb
41
+ - lib/passes/github.rb
42
+ - lib/passes/rails.rb
43
+ - README.textile
44
+ has_rdoc: false
45
+ homepage: http://github.com/simonmenke/gm
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project: gm
66
+ rubygems_version: 1.2.0
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: Build gems with ease.
70
+ test_files: []
71
+