GithubHelp home page GithubHelp logo

kevinhyunilkim / stimpack Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rubyatscale/packs-rails

0.0 1.0 0.0 261 KB

Stimpack establishes and implements a set of conventions for splitting up large monoliths.

License: MIT License

Shell 0.01% Ruby 99.99%

stimpack's Introduction

Stimpack

stimpack establishes and implements a set of conventions for splitting up large monoliths built on top of packwerk. With stimpack, new packages' autoload paths are automatically added to Rails, so your code will immediately become usable and loadable without additional configuration.

Here is an example application that uses stimpack:

package.yml # root level pack
app/ # Unpackaged code
  models/
  ...
packs/
  my_domain/
    package.yml # See the packwerk docs for more info
    deprecated_references.yml # See the packwerk docs for more info
    app/
      public/ # Recommended location for public API
        my_domain.rb # creates the primary namespaces
        my_domain/
          my_subdomain.rb
      services/ # Private services
        my_domain/
          some_private_class.rb
      models/ # Private models
        some_other_non_namespaced_private_model.rb # this works too
        my_domain/
          my_private_namespacd_model.rb
      controllers/
      views/
    config/
      initializers/ # Initializers can live in packs and load as expected
    lib/
      tasks/
    spec/ # With stimpack, specs for a pack live next to the pack
      public/
        my_domain_spec.rb
        my_domain/
          my_subdomain_spec.rb
      services/
        my_domain/
          some_private_class_spec.rb
      models/
        some_other_non_namespaced_private_model_spec.rb
        my_domain/
          my_private_namespaced_model_spec.rb
      factories/ # Stimpack will automatically load pack factories into FactoryBot
        my_domain/
          my_private_namespaced_model_factory.rb
  my_other_domain/
    ... # other pack's have a similar structure
  my_other_other_domain/
    ...

Usage

Setting up stimpack is straightforward. Simply by including stimpack in your Gemfile in all environments, stimpack will automatically hook into and configure Rails.

From there, you can create a ./packs folder and structure it using the conventions listed above.

If you wish to use a different directory name, eg components instead of packs, you can customize this in your config/application.rb file:

# Customize Stimpack's root directory. Note that this has to be done _before_ the Application
# class is declared.
Stimpack.config.root = "components"

module MyCoolApp
  class Application < Rails::Application
    # ...
  end
end

Splitting routes

stimpack allows you to split your application routes for every pack. You just have to create a file describing your routes and then draw them in your root config/routes.rb file.

# packs/my_domain/config/routes/my_domain.rb
resources :my_resource

# config/routes.rb
draw(:my_domain)

Making your Package an Engine

Add engine: true to your package.yml to make it an actual Rails engine:

# packs/my_pack/package.yml
enforce_dependencies: true
enforce_privacy: true
metadata:
  engine: true

RSpec Integration

Simply add --require stimpack/rspec to your .rspec. Or, if you'd like, pass it as an argument to rspec:

$ rspec --require stimpack/rspec ...

Integration will allow you to run tests as such:

# Run all specs in your entire application (packs and all):
rspec

# Run just that one test:
rspec spec/some/specific_spec.rb

# Run all tests under the "foobar" pack and all the tests of its nested packs:
rspec packs/foobar

# Same as above but also adds the "binbaz" pack:
rspec packs/foobar pack/binbaz

# Run all test files inside the "packs/foobar/spec" directory:
rspec packs/foobar/spec

# Run all specs under the "packs/foobar/nested_pack" pack:
rspec packs/foobar/nested_pack

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Gusto/stimpack.

stimpack's People

Contributors

ngan avatar geesu avatar julianpasquale avatar marcreynolds avatar matiaseche avatar oleg-vinted avatar

Watchers

James Cloos avatar

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.