Giter VIP home page Giter VIP logo

Comments (12)

gabebw avatar gabebw commented on July 3, 2024

Hi! I wrote most of fake_braintree. Thank you for the compliment on the README.

The short answer is that I don't have a recommendation for something like suspenders for gems (but others might!). That's not a bad idea, though. There are a bunch of projects on Ruby Toolbox but they look unmaintained.

The gem structure itself (lib folder) is handled by bundler and the like

As you might know, bundle gem hi will create a basic gem structure like this:

.
├── Gemfile
├── LICENSE.txt
├── README.md
├── Rakefile
├── hi.gemspec
└── lib
    ├── hi
    │   └── version.rb
    └── hi.rb

After running that, I run rspec --init in the base gem folder to get RSpec bootstrapped, copy in CONTRIBUTING.md from another thoughtbot project, and start TDDing my features.

It's worth noting, too, that a lot of our gems start out much (much) rougher than they are now. For example, fake_braintree started without a README and without any tests (!!): highfidelity/fake_braintree@8a222b5

from guides.

JuanitoFatas avatar JuanitoFatas commented on July 3, 2024

https://github.com/ruby-ore/ore This ore gem could be the starting point to customize your gem creation. I found this gem while reading Postmodern - You don't have to use Bundler to create new RubyGems.

from guides.

mcmire avatar mcmire commented on July 3, 2024

I don't know if it's a good idea to write our own gem generator (there are about a billion out there already), but I think this would be good material for a blog post.

from guides.

 avatar commented on July 3, 2024

Thanks for the feedback @gabebw @JuanitoFatas and @mcmire

Also, that makes me feel better @gabebw that you started in a must less polished state. I suppose it's true that even thoughtbot employees are mere mortals and sometimes don't write tests! 🎱 hahah

FWIW, @mcmire, I would totally keep that blog post as the defacto reference if you guys did write one. As a community we all look up to your open source contributions, and you guys have really nailed down - to a science - how to contribute and create open source software. So, seeing more written about that on the blog, would be just fantastic.

from guides.

dideler avatar dideler commented on July 3, 2024

+1 for a blog post - I think @gabebw got a good start going.

I've read blog posts & guides for creating a gem but often have to re-read them.
Most recently on my to-read list for gem building are

A concise post by thoughtbot would probably be the guide I refer to.

from guides.

bf4 avatar bf4 commented on July 3, 2024

If anyone cares, I started one once, but haven't revisited it in a while https://github.com/howto-ruby/rubygems-style-guide

from guides.

gabebw avatar gabebw commented on July 3, 2024

Thanks for your feedback, everybody! I may just write that blog post.

While we're all here at the virtual table, are people more interested in how to write a ruby gem or how to extract code from existing projects and then stick it in a rubygem?

from guides.

bf4 avatar bf4 commented on July 3, 2024

bundler itself uses a Thor to apply the new_gem template just like rails templates do, which suspenders uses. I've been meaning to generalize that code... right now I have something like the following... behaves similarly to a rails template.

# Usage:
# ruby __FILE__ NAME
# https://github.com/erikhuda/thor/wiki/Generators
# http://blog.tamouse.org/swaac/2014/03/08/playing-around-with-thor-generators/
# Inheriting from Thor::Group causes the defined methods to be executed in order
# rather than subcommands, when inheriting from 'Thor'
# e.g. https://github.com/bundler/bundler/blob/91633430cb/lib/bundler/cli.rb#L339-L352
#      https://github.com/bundler/bundler/blob/91633430cb/lib/bundler/cli/gem.rb#L18-L103
#      https://github.com/bundler/bundler/blog/91633430cb/lib/bundler/templates/newgem/Gemfile.tt
# class Bundler::CLI < Thor
#   class Gem
#     def initialize(options, gem_name, thor)
#      def run
#        opts = { :name => name, etc.
#        templates = { "Gemfile.tt" => "Gemfile", etc
#        templates.each do |src, dst|
#          thor.template("newgem/#{src}", target.join(dst), opts)
#        end
#   def gem(name)
#      Gem.new(options, name, self).run
#   end
#   def self.source_root
#     File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
#   end
require 'thor'
require 'thor/group'
class Gemnerator < Thor::Group
  include Thor::Actions
add_runtime_options!
  class_option :verbose, default: false

  # expect one argument upon invocation,
  argument :name
  attr_reader :template_file

  def initialize(args = [], options = {}, config = {})
    @template_file = config.fetch(:template_file)
    super
    # Will apply template in File.join(destination_root, name)
    self.destination_root = config[:projects_root]
  end

  desc <<-FOO
Description:
  This generator makes or updates gems from a template
FOO

 def self.source_root
    File.expand_path("../templates/new_gem",__FILE__)
  end

  def app_name
    @app_name ||= snake_name
  end

  def apply_template
    apply(template_file, verbose: options[:verbose])
  end

  # munging on potential input from the user
  # 'Able & Louis: Go @@CRAXY@@' becomes
  # ["Able", "Louis", "Go", "CRAXY"]
  def name_components
    @_name_components ||= name.scan(/[[:alnum:]]+/)
  end

  # ["Able", "Louis", "Go", "CRAXY"] become
  # able_louis_go_craxy
  def snake_name
    @_snake_name ||= name_components.map(&:downcase).join("_")
  end
end
projects_root = ENV.fetch('PROJECT_DIR')
template = ENV.fetch("LOCATION")
fail "No template LOCATION value given. Please set LOCATION either as path to a file or a URL" if template.nil?
fail "Template #{template} does not exist" unless File.readable?(template)
template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}
args = ARGV
config = {
  projects_root: projects_root,
  template_file: template
}
Gemnerator.start(args, config)

from guides.

 avatar commented on July 3, 2024

@gabebw Awesome mate!

To answer your question, for me, it's mainly a problem with the extraction of code. I also don't really know all the best practices around open sourcing gems so obviously there are multiple barriers to entry for someone in my position. BUT I think honestly extracting code from projects can be challenging, and is often I find a more likely scenario. I very rarely am just sitting around and think of a perfect idea for a gem - albeit that could be fairly common.

I think that question is quite nuanced because the answers to both of the questions "How to write a gem" and "How to extract code from a project for a gem" could essentially be answered with the same article/screencast/video/etc, theoretically. So it is hard for me to find one of those to place more value in, than the other.

from guides.

dideler avatar dideler commented on July 3, 2024

are people more interested in how to write a ruby gem or how to extract code from existing projects and then stick it in a rubygem?

Probably the latter, because I assume less guides exist for that compared to creating a new gem. But either topic would be a good read IMO.

from guides.

jferris avatar jferris commented on July 3, 2024

Thanks for the discussion! I'm going to close this, as there doesn't seem to be anything we need to change in the guides to address this, but feel free to continue commenting.

from guides.

 avatar commented on July 3, 2024

Awesome, thanks @jferris!

Looking forward to a potential blog post on this topic when @gabebw isn't slammed with work! :) Thanks guys.

from guides.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.