MicroGems:
Eliminating barriers
(I lied)
- this is really a talk about reducing friction
- ...so you spend more time doing real work...
- and less time doing busywork
Takeaways from this talk
- get annoyed more often
- let annoyance guide your tools improvement
- i want you to make a gem in the next 7 days
MicroGems
- least amount of work to make a gem.
- share code between projects and with others.
- ...has some drawbacks
#acts_as_boolean example
class Comment < ActiveRecord::Base
extend ActsAsBoolean
acts_as_boolean :is_published
end
comment = Comment.new
comment.is_published? # => false
comment.is_published = 'yes'
comment.is_published? #=> true
gist.github.com/1302883
module ActsAsBoolean
def acts_as_boolean(*attributes)
[*attributes].each do |attribute|
# Define the = setter method
attr_writer attribute
# Define the ? accessor method
define_method("#{attribute}?") { !!instance_variable_get("@#{attribute}") }
end
end
end
ActiveRecord::Base.send :extend, ActsAsBoolean
#bang example
class Comment < ActiveRecord::Base
extend Bang
bang :permalink_title => :permalink
before_save :permalink_title!
def permalink_title
title.parameterize
end
end
gist.github.com/1232884
module Bang
def bang(attributes)
[*attributes].each do |attribute|
key, value = attribute
define_method("#{key}!") { update_attribute(value || key, send(key)) }
end
end
end
What about my Gemfile?
...
gem 'acts_as_boolean', :git => 'git://gist.github.com/1302883.git'
...
(there are drawbacks)
- what about versioning?
- not as "stable" as RubyGems.org? transitory?
- weak/no: forking, pull requests, issues
- hard to find?
micro-cutter
Outputs a gem skeleton because:
- i'm forgetful/lazy, so I need a crutch.
- for me to use gems, it has to be easy
- ...and I needed to learn about gems
Usina Mini-Cutter
# Call the executable, passing a camel cased class name:
mini-cutter ActsAsBoolean
# This creates boilerplate files (overwriting any already there):
README.md
acts_as_boolean.gemspec
acts_as_boolean.rb
acts_as_boolean_spec.rb
Takeaways from this talk
- get annoyed more often
- let annoyance guide your tools improvement
- i want you to make a gem in the next 7 days
Credits
- MicroGems: http://jeffkreeftmeijer.com/2011/microgems-five-minute-rubygems/
- Photo 1: http://www.flickr.com/photos/rengber/5971502235/
- Photo 2: http://www.flickr.com/photos/nicholas_t/3427375143/