gemusta 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ group :test do
4
+ gem "rspec"
5
+ end
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ gemusta
2
+ =======
3
+
4
+ #What is this?
5
+ A basic and project-agnostic gemspec generator.
6
+
7
+ #Why is this?
8
+ Some gemspec files shell out git to find the files that are used by the gem. In some circumstances [read more here](http://tenderlovemaking.com/2011/12/05/profiling-rails-startup-with-dtrace/) this can cause performance issues.
9
+
10
+ But handle a gemspec should be a easy thing, I don't believe that we need add dependencies in our projects just to generate a good gemspec. This gem is only a collection of tasks, we can use this only in development environment. Leaving our project code totally independent of this.
11
+
12
+ #How is this?
13
+ You install the gem:
14
+
15
+ gem install gemusta
16
+
17
+ ###Perfect world approach
18
+ And now you have a executable `gemusta`. Your project don't need to know about this gem, neither your team, nobody. You just use:
19
+
20
+ gemusta
21
+
22
+ An `[your_project].gemspec` file will be created. Gemusta is opinionated and it thinks you are using git, if not, this step is not enough.
23
+
24
+ ###Customizing an erb for your project
25
+ You can create an erb file, edit it and then regenerate your gemspec:
26
+
27
+ gemusta -e
28
+
29
+ This will create a new and shine `[your_project].gemspec.erb` template for you. Edit it and then rerun `gemusta`. Every time you run this command it will search for a .erb file on your project or fallback to the internal one to produce a gemspec file.
30
+
31
+ # The End
32
+ And this is all, period.
data/Rakefile.rb ADDED
@@ -0,0 +1,9 @@
1
+ task :default => [:specs]
2
+ task :specs => [:"specs:all"]
3
+ namespace :specs do
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new "all" do |t|
6
+ t.pattern = "spec/**/*_spec.rb"
7
+ t.rspec_opts = ['--color', '--format documentation', '--require spec_helper']
8
+ end
9
+ end
data/bin/gemusta ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path("../../lib", __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+
5
+ require 'gemusta'
6
+ require 'gemusta/cli'
7
+
8
+ begin
9
+ Gemusta::CLI.new.run
10
+ rescue Interrupt => e
11
+ exit 1
12
+ rescue SystemExit => e
13
+ exit e.status
14
+ rescue Exception => e
15
+ raise e
16
+ end
@@ -0,0 +1,92 @@
1
+ require 'optparse'
2
+
3
+ module Gemusta
4
+
5
+ class CLI
6
+ class << self
7
+ attr_accessor :variables
8
+ end
9
+
10
+ def project_name
11
+ File.basename(File.expand_path("."))
12
+ end
13
+
14
+ # This one is directly from: https://github.com/mojombo/rakegem/blob/master/Rakefile
15
+ def project_version
16
+ line = File.read("lib/#{project_name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def create_gemspec
21
+ template_file = File.exists?(erb_name) ? erb_name : template_path
22
+ puts "adskfnalkfakldfjakdsjfalkjfdakljfklasdjfklasjdfklasdf"
23
+ puts IO.read(template_file)
24
+ erb = ERB.new(IO.read(template_file))
25
+ erb_result = erb.result(template_variables)
26
+ puts erb_result
27
+ File.open(gemspec_name, "w") do |file|
28
+ file.write(erb_result)
29
+ end
30
+ end
31
+
32
+ def create_erb
33
+ unless File.exists? erb_name
34
+ File.open(erb_name, "w") do |file|
35
+ file.write IO.read(template_path)
36
+ end
37
+ end
38
+ end
39
+
40
+ def run(args=ARGV)
41
+ options = parse_options ARGV,
42
+ :erb => false,
43
+ :gemspec => true
44
+ create_erb if options[:erb]
45
+ create_gemspec if options[:gemspec]
46
+ end
47
+
48
+ private
49
+ def template_variables
50
+ cli = self
51
+ vars = CLI.variables || {}
52
+
53
+ Object.new.instance_eval {
54
+ @name = vars[:name] || cli.project_name
55
+ @version = vars[:version] || cli.project_version
56
+
57
+ binding
58
+ }
59
+ end
60
+
61
+ def parse_options(args, options={})
62
+ parser = OptionParser.new do |opts|
63
+ opts.banner = "Usage: gemusta [options]"
64
+
65
+ opts.on "-e", "--erb", "Creates erb file" do
66
+ options[:erb] = true
67
+ end
68
+
69
+ opts.on "-a", "--all", "Creates both: erb and gemspec files" do
70
+ options[:erb] = true
71
+ options[:gemspec] = true
72
+ end
73
+ end
74
+
75
+ parser.parse!(args)
76
+ options
77
+ end
78
+
79
+ def template_path
80
+ File.join(File.expand_path('../', __FILE__), "gemspec_template_base.erb")
81
+ end
82
+
83
+ def erb_name
84
+ "#{gemspec_name}.erb"
85
+ end
86
+
87
+ def gemspec_name
88
+ "#{self.project_name}.gemspec"
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,46 @@
1
+ # -*- encoding: utf-8 -*-
2
+ <%
3
+ def git_files(param=nil)
4
+ `git ls-files #{param}`.split("\n")
5
+ end
6
+
7
+ def files
8
+ @files || git_files.reject do |file|
9
+ file =~ /\.(gitignore|rvmrc)|Gemfile.lock/
10
+ end
11
+ end
12
+
13
+ def test_files
14
+ @test_files || git_files("-- spec/*")
15
+ end
16
+
17
+ def executable_files
18
+ @executable_files || git_files("-- bin/*").map { |file| file.gsub("bin/", "") }
19
+ end
20
+ %>
21
+ lib = File.expand_path('../lib/', __FILE__)
22
+ $:.unshift lib unless $:.include?(lib)
23
+
24
+ Gem::Specification.new do |s|
25
+ s.name = "<%= @name %>"
26
+ s.version = "<%= @version %>"
27
+ s.platform = Gem::Platform::RUBY
28
+ s.authors = ["your name here"]
29
+ s.email = ["you_email@your_site", "omg@team_member.com"]
30
+ s.homepage = "http://your_site"
31
+ s.summary = "awesome summary"
32
+ s.description = "And awesome description for your awesome gem"
33
+
34
+ s.required_rubygems_version = ">= 0"
35
+
36
+ s.add_development_dependency "rspec"
37
+
38
+ s.require_path = 'lib'
39
+
40
+ s.files = <%= files %>
41
+ s.test_files = <%= test_files %>
42
+
43
+ <% if executable_files %>
44
+ s.executables = <%= executable_files %>
45
+ <% end %>
46
+ end
data/lib/gemusta.rb ADDED
@@ -0,0 +1,76 @@
1
+ require 'erb'
2
+
3
+ module Gemusta
4
+ VERSION = "0.0.1"
5
+ NAME = "gemusta"
6
+
7
+ class Generator
8
+
9
+ class << self
10
+ def project_name
11
+ File.expand_path(".")
12
+ end
13
+
14
+ def gemspec_file_name=(gemspec_file_name)
15
+ @gemspec_file_name ||= "#{gemspec_file_name}.gemspec"
16
+ end
17
+
18
+ def gemspec_file_name
19
+ @gemspec_file_name ||= "#{::NAME}.gemspec"
20
+ end
21
+
22
+ def template_file_path
23
+ @template_file_path ||=
24
+ File.join(File.expand_path(".", __FILE__), "gemspec.erb")
25
+ end
26
+
27
+ end
28
+
29
+ def generate(erb="gemspec.erb", gemspec_file=self.gemspec_file_name)
30
+ template_path =
31
+ template = ERB.new(IO.read(template_path))
32
+
33
+ File.open("#{gemspec_file}.gemspec", "w") do |file|
34
+ scope_vars = gemspec_scope(files, test_files)
35
+ file.write(template.result(scope_vars))
36
+ end
37
+ end
38
+
39
+ def specification(gemspec_file=self.gemspec_file_name)
40
+ IO.read()
41
+ end
42
+
43
+ private
44
+ def git_files(param=nil)
45
+ all_files = `git ls-files #{param}`.split("\n")
46
+ end
47
+
48
+ def files
49
+ git_files.reject do |file|
50
+ file =~ /\.(gitignore|rvmrc)|Gemfile.lock/
51
+ end
52
+ end
53
+
54
+ def test_files
55
+ git_files("-- spec/*")
56
+ end
57
+
58
+ def executable_files
59
+ git_files("-- bin/*")
60
+ end
61
+
62
+ def gemspec_scope(files, test_files)
63
+ Object.new.instance_eval {
64
+ name = ::NAME
65
+ version = ::VERSION
66
+ files = files || []
67
+
68
+ test_files = test_files || []
69
+ executable_files = executable_files || []
70
+
71
+ binding
72
+ }
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,97 @@
1
+ module Gemusta
2
+
3
+ describe CLI do
4
+ def project_name; "gemusta"; end
5
+ def gemspec_name; "#{project_name}.gemspec"; end
6
+ def erb_name; "#{project_name}.gemspec.erb"; end
7
+ def gem_name; "#{project_name}-#{Gemusta::VERSION}.gem"; end
8
+
9
+ def executable
10
+ File.join(File.expand_path("../../../bin", __FILE__), project_name)
11
+ end
12
+
13
+ def remove_files
14
+ FileUtils.rm(gemspec_name) if File.exists?(gemspec_name)
15
+ FileUtils.rm(erb_name) if File.exists?(erb_name)
16
+ end
17
+
18
+ before :all do
19
+ remove_files
20
+ @cli = CLI.new
21
+ end
22
+
23
+ it "discover the project name by the execution dir" do
24
+ @cli.project_name.should == project_name
25
+ end
26
+
27
+ it "use 'main project file' convension to discover the version" do
28
+ @cli.project_version.should == Gemusta::VERSION
29
+ end
30
+
31
+ context "file generation" do
32
+
33
+ it "should create gemusta.gemspec file" do
34
+ @cli.create_gemspec
35
+ File.exists?(gemspec_name).should be_true
36
+ end
37
+
38
+ it "should create erb file" do
39
+ @cli.create_erb
40
+ File.exists?(erb_name).should be_true
41
+ end
42
+
43
+ it "use a default template as content for erb" do
44
+ @cli.create_erb
45
+ template_path =
46
+ File.join(File.expand_path("../"), "gemusta/lib/gemusta/gemspec_template_base.erb")
47
+ IO.read(erb_name).should == IO.read(template_path)
48
+ end
49
+ end # "file generation"
50
+
51
+ context "command (line) execution" do
52
+
53
+ it "gemusta: create gemspec" do
54
+ executable
55
+ system executable
56
+ File.exists?(gemspec_name).should be_true
57
+ end
58
+
59
+ it "gemusta -e: create erb" do
60
+ system "#{executable} -e"
61
+ File.exists?(erb_name).should be_true
62
+ end
63
+
64
+ it "gemusta -a: create both (erb and gemspec)" do
65
+ system "#{executable} -a"
66
+ File.exists?(gemspec_name).should be_true
67
+ File.exists?(erb_name).should be_true
68
+ end
69
+ end # command (line) execution
70
+
71
+ context "generating gemspec from erb" do
72
+ it "generate valid gemspec, without local erb" do
73
+ system executable
74
+ spec = eval(IO.read(gemspec_name))
75
+ spec.version.to_s.should == Gemusta::VERSION
76
+ end
77
+
78
+ it "generate the gemspec from local erb" do
79
+ @cli.create_gemspec
80
+ File.open(gemspec_name, "a") { |file| file.write "\n123" }
81
+ result = eval(IO.read(gemspec_name))
82
+ result == 123
83
+ end
84
+
85
+ it "generate a gemspec recongnizable for rubygems" do
86
+ system executable
87
+ `gem build #{gemspec_name}`
88
+ File.exists?(gem_name).should be_true
89
+ end
90
+ end # generating gemspec from erb
91
+
92
+ after do
93
+ remove_files
94
+ FileUtils.rm(gem_name) if File.exists?(gem_name)
95
+ end
96
+ end # describe CLI
97
+ end
@@ -0,0 +1,3 @@
1
+ $: << File.join(File.expand_path('../', __FILE__), 'lib')
2
+ require 'gemusta'
3
+ require 'gemusta/cli'
metadata CHANGED
@@ -1,64 +1,69 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gemusta
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 0
9
- version: 0.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Ricardo Valeriano
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-12-30 00:00:00 -02:00
18
- default_executable:
19
- dependencies: []
20
-
21
- description:
22
- email: ricardo.valeriano@gmail.com
23
- executables: []
24
-
12
+ date: 2011-12-31 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70238290094780 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70238290094780
25
+ description: ! 'gemusta was created to allow you generate your gemspec in advance,
26
+ based on a erb template '
27
+ email:
28
+ - ricardo.valeriano@gmail.com
29
+ executables:
30
+ - gemusta
25
31
  extensions: []
26
-
27
32
  extra_rdoc_files: []
28
-
29
- files: []
30
-
31
- has_rdoc: true
32
- homepage:
33
+ files:
34
+ - Gemfile
35
+ - README.md
36
+ - Rakefile.rb
37
+ - bin/gemusta
38
+ - lib/gemusta.rb
39
+ - lib/gemusta/cli.rb
40
+ - lib/gemusta/gemspec_template_base.erb
41
+ - spec/gemusta/cli_spec.rb
42
+ - spec/spec_helper.rb
43
+ homepage: https://github.com/ricardovaleriano/gemusta
33
44
  licenses: []
34
-
35
45
  post_install_message:
36
46
  rdoc_options: []
37
-
38
- require_paths:
47
+ require_paths:
39
48
  - lib
40
- required_ruby_version: !ruby/object:Gem::Requirement
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- segments:
45
- - 1
46
- - 8
47
- - 7
48
- version: 1.8.7
49
- required_rubygems_version: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- segments:
54
- - 0
55
- version: "0"
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
56
61
  requirements: []
57
-
58
62
  rubyforge_project:
59
- rubygems_version: 1.3.6
63
+ rubygems_version: 1.8.10
60
64
  signing_key:
61
65
  specification_version: 3
62
- summary: Creates a gemspec file, the point is to avoid shelling out git and such
63
- test_files: []
64
-
66
+ summary: A basic and project-agnostic gemspec generator.
67
+ test_files:
68
+ - spec/gemusta/cli_spec.rb
69
+ - spec/spec_helper.rb