mechanic 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,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 GB - Sotware As A Service, Lda.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ ![engine](http://allemandindustries.com/html/images/cartoon-mechanic4.jpg)
2
+ # Mechanic
3
+
4
+ Mechanic creates engines the Group Buddies way. It's perfect if you just want to hit the groud running and not worrying on doing those same configuration steps everytime.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'mechanic'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mechanic
20
+
21
+ Usage
22
+ -----
23
+
24
+ TODO: Write usage instructions here
25
+
26
+ Dependencies
27
+ ------------
28
+
29
+ Some gems included in Mechanic have native extensions. You should have GCC installed on your
30
+ machine before generating an app with Mechanic.
31
+
32
+ Use [OS X GCC Installer](/kennethreitz/osx-gcc-installer/) for Snow Leopard
33
+ (OS X 10.6).
34
+
35
+ Use [Command Line Tools for XCode](https://developer.apple.com/downloads/index.action)
36
+ for Lion (OS X 10.7) or Mountain Lion (OS X 10.8).
37
+
38
+ We use [Capybara Webkit](/thoughtbot/capybara-webkit) for full-stack Javascript
39
+ integration testing. It requires QT. Instructions for installing QT are
40
+ [here](/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit).
41
+
42
+ PostgreSQL needs to be installed and running for the `db:create` rake task.
43
+
44
+ Issues
45
+ ------
46
+
47
+ If you have problems, please create a [Github Issue](/zamith/mechanic/issues).
48
+
49
+ Contributing
50
+ ------------
51
+
52
+ 1. Fork it
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create new Pull Request
57
+
58
+ Credits
59
+ -------
60
+
61
+ ![groupbuddies](http://www.groupbuddies.com/logo.png)
62
+
63
+ Mechanic is maintained and funded by [GB - Software As A Service, Lda.](http://groupbuddies.com)
64
+
65
+ Mechanic's idea came from thoughtbot's [suspenders](/thoughtbot/suspenders), so some of the code is based
66
+ on it.
67
+
68
+ License
69
+ -------
70
+
71
+ Mechanic is Copyright © 2008-2012 Group Buddies. It is free software, and may be
72
+ redistributed under the terms specified in the LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/mechanic ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join('..', 'lib', 'mechanic', 'generators', 'engine_generator'), File.dirname(__FILE__))
4
+ require File.expand_path(File.join('..', 'lib', 'mechanic', 'actions'), File.dirname(__FILE__))
5
+ require File.expand_path(File.join('..', 'lib', 'mechanic', 'engine_builder'), File.dirname(__FILE__))
6
+
7
+ templates_root = File.expand_path(File.join("..", "templates"), File.dirname(__FILE__))
8
+ Mechanic::EngineGenerator.source_root templates_root
9
+ Mechanic::EngineGenerator.source_paths << Rails::Generators::PluginNewGenerator.source_root << templates_root
10
+
11
+ Mechanic::EngineGenerator.start
@@ -0,0 +1,35 @@
1
+ module Mechanic
2
+ module Actions
3
+ def concat_file(source, destination)
4
+ contents = IO.read(find_in_source_paths(source))
5
+ append_file destination, contents
6
+ end
7
+
8
+ def replace_in_file(relative_path, find, replace)
9
+ path = File.join(destination_root, relative_path)
10
+ contents = IO.read(path)
11
+ unless contents.gsub!(find, replace)
12
+ raise "#{find.inspect} not found in #{relative_path}"
13
+ end
14
+ File.open(path, "w") { |file| file.write(contents) }
15
+ end
16
+
17
+ def action_mailer_host(rails_env, host)
18
+ inject_into_file(
19
+ "config/environments/#{rails_env}.rb",
20
+ "\n\n config.action_mailer.default_url_options = { :host => '#{host}' }",
21
+ :before => "\nend"
22
+ )
23
+ end
24
+
25
+ def download_file(uri_string, destination)
26
+ uri = URI.parse(uri_string)
27
+ http = Net::HTTP.new(uri.host, uri.port)
28
+ http.use_ssl = true if uri_string =~ /^https/
29
+ request = Net::HTTP::Get.new(uri.path)
30
+ contents = http.request(request).body
31
+ path = File.join(destination_root, destination)
32
+ File.open(path, "w") { |file| file.write(contents) }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,98 @@
1
+ module Mechanic
2
+ class EngineBuilder < Rails::PluginBuilder
3
+ include Mechanic::Actions
4
+
5
+ def readme
6
+ template 'README.md.erb', 'README.md'
7
+ end
8
+
9
+ def raise_delivery_errors
10
+ replace_in_file "#{dummy_path}/config/environments/development.rb",
11
+ 'raise_delivery_errors = false', 'raise_delivery_errors = true'
12
+ end
13
+
14
+ def add_custom_gems
15
+ additions_path = find_in_source_paths 'gemspec_additions'
16
+ new_gems = File.open(additions_path).read
17
+ inject_into_file "#{name}.gemspec", "\n#{new_gems}",
18
+ :after => /s.add_dependency "rails", "~> 3.2.8"/
19
+ end
20
+
21
+ def add_capybara_webkit_gem
22
+ inject_into_file "#{name}.gemspec", " s.add_development_dependency 'capybara-webkit'\n",
23
+ :before => /^end$/
24
+ end
25
+
26
+ def use_postgres_config_template
27
+ template 'postgresql_database.yml.erb', "#{dummy_path}/config/database.yml",
28
+ :force => true
29
+ end
30
+
31
+ def create_database
32
+ inside dummy_path do
33
+ bundle_command 'exec rake db:create'
34
+ end
35
+ end
36
+
37
+ def configure_action_mailer
38
+ inside dummy_path do
39
+ action_mailer_host 'development', "#{name}.local"
40
+ action_mailer_host 'test', 'www.example.com'
41
+ action_mailer_host 'production', "#{name}.com"
42
+ end
43
+ end
44
+
45
+ def generate_rspec
46
+ inside dummy_path do
47
+ bundle_command 'exec rails g rspec:install'
48
+ inject_into_file '.rspec', " --drb", :after => '--color'
49
+ append_file "spec/spec_helper.rb", "\n load '\#{Rails.root}/db/seeds.rb'"
50
+ end
51
+ end
52
+
53
+ def configure_time_zone
54
+ time_zone_config = <<-RUBY
55
+ config.active_record.default_timezone = :utc
56
+ RUBY
57
+ inject_into_class "#{dummy_path}/config/application.rb", "Application", time_zone_config
58
+ end
59
+
60
+ def configure_capybara_webkit
61
+ append_file "#{dummy_path}/spec/spec_helper.rb", "\n Capybara.javascript_driver = :webkit\n"
62
+ end
63
+
64
+ def add_email_validator
65
+ if mountable?
66
+ copy_file 'email_validator.rb', "app/#{name}/validators/email_validator.rb"
67
+ else
68
+ copy_file 'email_validator.rb', 'app/validators/email_validator.rb'
69
+ end
70
+ end
71
+
72
+ def setup_default_rake_task
73
+ append_file 'Rakefile', "task(:default).clear\ntask :default => [:spec]"
74
+ end
75
+
76
+ def gitignore_files
77
+ concat_file 'mechanic_gitignore', '.gitignore'
78
+ end
79
+
80
+ def init_git
81
+ run 'git init'
82
+ end
83
+
84
+ def create_github_repo(repo_name)
85
+ path_addition = override_path_for_tests
86
+ run "#{path_addition} hub create #{repo_name}"
87
+ end
88
+
89
+ private
90
+
91
+ def override_path_for_tests
92
+ if ENV['TESTING']
93
+ support_bin = File.expand_path(File.join('..', '..', '..', 'features', 'support', 'bin'))
94
+ "PATH=#{support_bin}:$PATH"
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,115 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/rails/plugin_new/plugin_new_generator'
3
+
4
+ module Mechanic
5
+ class EngineGenerator < Rails::Generators::PluginNewGenerator
6
+
7
+ class_option :database, :type => :string, :aliases => '-d', :default => "sqlite3",
8
+ :desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
9
+
10
+ class_option :github, :type => :string, :aliases => '-G', :default => nil,
11
+ :desc => 'Create Github repository and add remote origin pointed to repo'
12
+
13
+ class_option :webkit, :type => :boolean, :aliases => '-W', :default => true,
14
+ :desc => 'Add the Capybara Webkit Javascript integration testing library'
15
+
16
+ class_option :skip_test_unit, :type => :boolean, :aliases => '-T', :default => true,
17
+ :desc => 'Skip Test::Unit files'
18
+
19
+ class_option :dummy_path, :type => :string, :default => "spec/dummy",
20
+ :desc => "Create dummy application at given path"
21
+
22
+ def finish_template
23
+ invoke :call_the_mechanic
24
+ super
25
+ end
26
+
27
+ def call_the_mechanic
28
+ invoke :setup_development_environment
29
+ invoke :customize_gemspec
30
+ invoke :setup_test_database
31
+ invoke :configure_engine
32
+ invoke :setup_git
33
+ invoke :create_github_repo
34
+ invoke :wrap_up
35
+ end
36
+
37
+ def setup_development_environment
38
+ say 'Setting up the development environment'
39
+ build :raise_delivery_errors
40
+ end
41
+
42
+ def customize_gemspec
43
+ build :add_custom_gems
44
+
45
+ if options[:webkit]
46
+ build :add_capybara_webkit_gem
47
+ end
48
+
49
+ bundle_command 'install'
50
+ end
51
+
52
+ def setup_test_database
53
+ say 'Setting up database in spec/dummy'
54
+
55
+ if 'postgresql' == options[:database]
56
+ build :use_postgres_config_template
57
+ end
58
+
59
+ build :create_database
60
+ end
61
+
62
+ def configure_engine
63
+ say 'Configuring engine'
64
+ build :configure_action_mailer
65
+ build :generate_rspec
66
+ build :configure_time_zone
67
+
68
+ if options[:webkit]
69
+ build :configure_capybara_webkit
70
+ end
71
+
72
+ build :add_email_validator
73
+ build :setup_default_rake_task
74
+ end
75
+
76
+ def setup_git
77
+ say 'Initializing git'
78
+ invoke :setup_gitignore
79
+ invoke :init_git
80
+ end
81
+
82
+ def create_github_repo
83
+ if options[:github]
84
+ say 'Creating Github repo'
85
+ build :create_github_repo, options[:github]
86
+ end
87
+ end
88
+
89
+ def wrap_up
90
+ say 'Congratulations! Your trip to shop was a success.'
91
+ end
92
+
93
+ def setup_gitignore
94
+ build :gitignore_files
95
+ end
96
+
97
+ def init_git
98
+ build :init_git
99
+ end
100
+
101
+ def run_bundle
102
+ # Let's not: We'll bundle manually at the right spot
103
+ end
104
+
105
+ private
106
+
107
+ def get_builder_class
108
+ Mechanic::EngineBuilder
109
+ end
110
+
111
+ def using_active_record?
112
+ !options[:skip_active_record]
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,3 @@
1
+ module Mechanic
2
+ VERSION = "0.0.1"
3
+ end
data/lib/mechanic.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "mechanic/version"
2
+
3
+ module Mechanic
4
+ # Your code goes here...
5
+ end
data/mechanic.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mechanic/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "mechanic"
8
+ gem.version = Mechanic::VERSION
9
+ gem.authors = ["Zamith"]
10
+ gem.email = ["zamith.28@gmail.com"]
11
+ gem.description = %q{Makes your engines better.}
12
+ gem.summary = %q{Mechanic creates engines the Group Buddies way.}
13
+ gem.homepage = "https://github.com/zamith/mechanic"
14
+
15
+ gem.files = `git ls-files`.split($/).
16
+ reject { |file| file =~ /^\./ }.
17
+ reject { |file| file =~ /^(rdoc|pkg)/ }
18
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ gem.require_paths = ["lib"]
21
+
22
+ gem.rdoc_options = ["--charset=UTF-8"]
23
+ gem.extra_rdoc_files = %w[README.md]
24
+
25
+ gem.add_dependency 'rails', '3.2.8'
26
+ gem.add_dependency 'bundler', '>= 1.1'
27
+ gem.add_dependency 'hub', '~> 1.10.2'
28
+
29
+ gem.add_development_dependency 'cucumber', '~> 1.1.9'
30
+ gem.add_development_dependency 'aruba', '~> 0.4.11'
31
+ end
@@ -0,0 +1,9 @@
1
+ Follow the Mechanic's Tip
2
+ =========================
3
+
4
+ Use the following guides for getting things done, programming well, and
5
+ programming in style.
6
+
7
+ * [Protocol](http://github.com/groupbuddies/guides/blob/master/protocol)
8
+ * [Best Practices](http://github.com/groupbuddies/guides/blob/master/best-practices)
9
+ * [Style](http://github.com/groupbuddies/guides/blob/master/style)
@@ -0,0 +1,7 @@
1
+ class EmailValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
4
+ record.errors[attribute] << (options[:message] || "is not an email")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ s.add_dependency "sass-rails"
2
+ s.add_dependency "formtastic"
3
+
4
+ s.add_development_dependency "thin"
5
+ s.add_development_dependency "rspec-rails"
6
+ s.add_development_dependency "email_spec"
7
+ s.add_development_dependency "capybara"
8
+ s.add_development_dependency "database_cleaner"
9
+ s.add_development_dependency "launchy"
10
+ s.add_development_dependency "jasmine-rails"
11
+ s.add_development_dependency "jasmine-jquery-rails"
12
+ s.add_development_dependency "shoulda-matchers"
13
+ s.add_development_dependency "timecop"
@@ -0,0 +1,23 @@
1
+ !.keep
2
+ *.DS_Store
3
+ *.swp
4
+ .env
5
+ coverage/*
6
+ spec/dummy/public/system
7
+ rerun.txt
8
+ tags
9
+ *.gem
10
+ *.rbc
11
+ .bundle
12
+ .config
13
+ .yardoc
14
+ Gemfile.lock
15
+ InstalledFiles
16
+ _yardoc
17
+ coverage
18
+ doc/
19
+ lib/bundler/man
20
+ pkg
21
+ rdoc
22
+ spec/reports
23
+ tmp
@@ -0,0 +1,11 @@
1
+ development: &default
2
+ adapter: postgresql
3
+ database: <%= app_name %>_development
4
+ encoding: utf8
5
+ min_messages: warning
6
+ pool: 5
7
+ timeout: 5000
8
+
9
+ test:
10
+ <<: *default
11
+ database: <%= app_name %>_test
@@ -0,0 +1,6 @@
1
+ # {
2
+ # :short_date => "%d, %m, %Y", # 13/04/10
3
+ # :long_date => "%a, %b %d, %Y" # Tue, Apr 13, 2010
4
+ # }.each do |format_name, format_string|
5
+ # Time::DATE_FORMATS[format_name] = format_string
6
+ # end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mechanic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Zamith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.8
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.8
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '1.1'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '1.1'
46
+ - !ruby/object:Gem::Dependency
47
+ name: hub
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.10.2
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.10.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: cucumber
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.1.9
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.1.9
78
+ - !ruby/object:Gem::Dependency
79
+ name: aruba
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.4.11
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.4.11
94
+ description: Makes your engines better.
95
+ email:
96
+ - zamith.28@gmail.com
97
+ executables:
98
+ - mechanic
99
+ extensions: []
100
+ extra_rdoc_files:
101
+ - README.md
102
+ files:
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - bin/mechanic
108
+ - lib/mechanic.rb
109
+ - lib/mechanic/actions.rb
110
+ - lib/mechanic/engine_builder.rb
111
+ - lib/mechanic/generators/engine_generator.rb
112
+ - lib/mechanic/version.rb
113
+ - mechanic.gemspec
114
+ - templates/README.md.erb
115
+ - templates/email_validator.rb
116
+ - templates/gemspec_additions
117
+ - templates/mechanic_gitignore
118
+ - templates/postgres_database.yml.erb
119
+ - templates/time_formats.rb
120
+ homepage: https://github.com/zamith/mechanic
121
+ licenses: []
122
+ post_install_message:
123
+ rdoc_options:
124
+ - --charset=UTF-8
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 1.8.24
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Mechanic creates engines the Group Buddies way.
145
+ test_files: []