Pluck It - Southeast Ruby 2017

Pluck It - Southeast Ruby 2017

How many times have you written the same bits of code, over and over, and thought, “You know, if only this was big enough to be a gem, I would pluck it out.” Often, we think of a RubyGem as a larger library of code that we “bolt on” to an app. And, these smaller code blobs become a hassle to distribute to the multiple apps that use them.

A small micro-library, done the right way, at the right time, can greatly improve an app.

But, when can you benefit from extracting a micro-library? And, how do you build and publish that code into a RubyGem? I’ll go through the process, from A to Z.

Fff206665889a0f5baeedf5b75483edd?s=128

Adam Cuppy

October 05, 2017
Tweet

Transcript

  1. @adamcuppy codingzeal.com

  2. github.com/acuppy @adamcuppy

  3. speakerdeck.com/ acuppy

  4. Pluck It Extracting micro-libraries and building rubygems @AdamCuppy

  5. None
  6. None
  7. Add /lib/gravatar.rb

  8. Moved from app/models/user.rb

  9. None
  10. https://rubygems.org/

  11. It’s a simple package: a self-contained collection of one or

    more files. rubygem:
  12. http://bundler.io/

  13. /path/to/myapp/Gemfile

  14. $ bundle install RubyGems

  15. App Bundle $ bundle install Bundler + RubyGems + MyApp

    RubyGems.org rails-5.1 rspec-core-3.2 Private Gem Server priv_gem-1.0 priv_gem2—1.0
  16. None
  17. None
  18. $ bundle gem hash_diff ——test

  19. $ bundle gem hash_diff ——test

  20. $ bundle gem hash_diff ——test

  21. $ bundle gem hash_diff ——test

  22. $ bundle gem hash_diff ——test

  23. $ bundle help gem

  24. None
  25. None
  26. None
  27. $ cd /path/to/my_gem $ bundle install $ rake

  28. None
  29. None
  30. None
  31. None
  32. Build: $ cd /path/to/my_gem $ gem build hash_diff.gemspec

  33. Publish: $ gem push hash_diff-0.1.0.gem

  34. $ bundle exec rake release

  35. https://rubygems.org/gems/hash_diff

  36. /path/to/myapp/Gemfile

  37. $ cd /path/to/myapp $ bundle install

  38. I’m Famous!

  39. None
  40. 1. Modify code 2. Increment VERSION constant 3. Rebuild and

    Release 4. Update apps: $ cd /path/to/app; bundle update my_gem New Release
  41. 1. Isolation from app code 2. Manage upgrades 3. Community

    support Pros…
  42. Extraction encourages isolation; isolation encourages a simple interface; and, a

    simple interface is more maintainable.
  43. 1. External dependencies to manage 2. Add’l development overhead 3.

    Community support Cons…
  44. When is the “right time?”

  45. It’s when the cost of maintaining an internal library, exceeds

    the cost of maintaining an external dependency.
  46. https://rubygems.org/gems/trueman

  47. https://rubygems.org/gems/gravasaurus_hex

  48. https://rubygems.org/gems/hash_diff

  49. http://guides.rubygems.org/

  50. http://bundler.io

  51. podcast.codingzeal.com We discuss an interesting article or link from the

    week in the world of business, software, teams and open source