├── templates ├── class_name.rb.erb ├── class_name_spec.rb.erb ├── README.md.erb └── class_name.gemspec.erb ├── micro-cutter.gemspec ├── bin └── micro-cutter └── README.md /templates/class_name.rb.erb: -------------------------------------------------------------------------------- 1 | class <%= @class_name %> 2 | 3 | end 4 | -------------------------------------------------------------------------------- /templates/class_name_spec.rb.erb: -------------------------------------------------------------------------------- 1 | require File.expand_path('<%= @class_name_underscore %>') 2 | 3 | describe <%= @class_name %> do 4 | it 'should have tests' do 5 | pending 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /templates/README.md.erb: -------------------------------------------------------------------------------- 1 | # <%= @class_name %> 2 | 3 | Description and usage: 4 | 5 | require '<%= @class_name_underscore %>' 6 | <%= @class_name %>.new 7 | 8 | # Running the tests 9 | 10 | Install the rspec gem 11 | 12 | gem install rspec 13 | 14 | Run the spec 15 | 16 | rspec <%= @class_name_underscore %>_spec.rb 17 | -------------------------------------------------------------------------------- /templates/class_name.gemspec.erb: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.name = '<%= @class_name_underscore %>' 3 | s.summary = '' 4 | s.description = '' 5 | s.version = '0.0.1' 6 | s.platform = Gem::Platform::RUBY 7 | 8 | s.files = ['<%= @class_name_underscore %>.rb'] 9 | s.require_path = '.' 10 | 11 | s.author = '' 12 | s.email = '' 13 | s.homepage = '' 14 | 15 | s.test_file = '<%= @class_name_underscore %>_spec.rb' 16 | s.add_development_dependency('rspec', ["~> 2.8"]) 17 | end 18 | 19 | -------------------------------------------------------------------------------- /micro-cutter.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.name = 'micro-cutter' 3 | s.summary = 'Micro Cutter: create the boilerplate files needed for a MicroGem' 4 | s.description = 'Quick tool for building out the minimal set of files needed to make a MicroGem' 5 | s.version = '0.1.2' 6 | s.platform = Gem::Platform::RUBY 7 | 8 | s.files = Dir['bin/*'] + Dir['templates/*'] 9 | s.executables << 'micro-cutter' 10 | 11 | s.authors = ['Tim Harvey'] 12 | s.email = 'tim@theharveys.org' 13 | s.homepage = 'https://github.com/tjh/micro-cutter' 14 | end 15 | -------------------------------------------------------------------------------- /bin/micro-cutter: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'erb' 4 | 5 | class MyVars 6 | def initialize(class_name, class_name_underscore) 7 | @class_name = class_name 8 | @class_name_underscore = class_name_underscore 9 | end 10 | end 11 | 12 | class_name = ARGV[0] 13 | # Dirt simple way to convert 'AbcDef' to 'abc_def' 14 | class_name_underscore = class_name.gsub(/(.)([A-Z])/, '\1_\2').downcase 15 | 16 | var_binding = MyVars.new(class_name, class_name_underscore).send(:binding) 17 | 18 | Dir.glob("#{File.dirname(__FILE__)}/../templates/*.erb") do |file| 19 | erb_template = ERB.new File.open(file, 'r').read 20 | erb_result = erb_template.result(var_binding) 21 | 22 | # Remove the path from the file string 23 | file_name = File.basename file 24 | 25 | # Remove .erb from the filename, and replace 26 | # the 'class_name' placeholder from the file name 27 | new_file_name = file_name.gsub(/.erb/, '').gsub(/class_name/, class_name_underscore) 28 | 29 | puts "Creating: #{new_file_name}" 30 | 31 | # Create a new file, writing the erb template result 32 | new_file = File.new(new_file_name, 'w') 33 | new_file.write erb_result 34 | new_file.close 35 | end 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Micro Cutter 2 | ------------ 3 | 4 | Create the base files needed for a micro gem (potentially stored in a 5 | gist). 6 | 7 | # Usage 8 | 9 | Call the executable, passing a camel cased class name: 10 | 11 | micro-cutter ActsAsBoolean 12 | 13 | This creates boilerplate files (overwriting any already there): 14 | 15 | * README.md 16 | * acts_as_boolean.gemspec 17 | * acts_as_boolean.rb 18 | * acts_as_boolean_spec.rb 19 | 20 | # Using a Gist to store your MicroGem 21 | 22 | Head to gist.github.com and create a gist: 23 | 24 | * Give it a good name 25 | * Set the filename to README.md 26 | * Add some dummy content 27 | * Click "Create Public Gist" (or private if you have trouble sharing) 28 | 29 | Update the gist from your new MicroGem: 30 | 31 | git clone git@gist.github.com:YOUR_GIST_ID.git YOUR_DESIRED_FOLDER_NAME 32 | cd YOUR_DESIRED_FOLDER_NAME 33 | micro-cutter YourClassName 34 | git add . 35 | git commit -v 36 | git push origin master 37 | 38 | # Credits 39 | 40 | * **[@jkreeftmeijer](http://twitter.com/jkreeftmeijer)** for coming up with the killer MicroGem concept
(http://jeffkreeftmeijer.com/2011/microgems-five-minute-rubygems/) 41 | * **[@moutten](http://twitter.com/moutten)** for helping me through the file name handling and generally making me a better Ruby developer every day 42 | * **[@mettaaudio](http://twitter.com/mettaaudio)** for not laughing too loudly as I hacked this together over lunch and made countless typos 43 | --------------------------------------------------------------------------------