Code Monkey home page Code Monkey logo

rplate's Introduction

RPlate

RPlate is an opinionated tool to generate ruby classes and modules and related specs from predefined templates.

Its goal is to remove the need to manually create everytime those files and fill them with a given content, like class definition, namespace scoping, method definition and so on.

It is tested to work on ruby 2.4+ in ubuntu and macosx platforms.

Note

To take full advantage of rplate features your naming conventions must follow the zeitwerk filestructure.

Good news to be mentioned is that from rails 6 zeitwerk gem is the default require engine and you are probably good to go :-)

Usage

The cli interface of rplate expects a list of underscored entities

rplate generate my_module my_class

will:

  • place the Myclass class in lib/my_module/my_class.rb
  • place the related spec file in spec/lib/my_module/my_class_spec.rb
  • scope MyClass inside the MyNamespace module

Once those files have been generated rplate will run rubocop on them according to the styleguide in rplate .rubocop.yml.

Note

Currently it is not supported the use of a custom rubocop styleguide but this does not mean that you cannot run your local styleguide by your own ;-)

Allowed arguments

Rplate accepts some arguments. Check that by calling the help:

rplate help generate

That will result in:

Usage:
  rplate generate [ENTITIES]

Options:
  -t, [--type=TYPE]                       # `class` or `module`
                                          # Default: class
  -m, [--required-methods=one two three]  # the class methods
  -r, [--root=ROOT]                       # example: `app/controllers`
                                          # Default: lib
  -i, [--inflections=one two three]       # example: -i rplate:RPlate api:API

generate a ruby entity with the given name

Type

You can define what kind of type your new entity should be: class or module

Required Methods

rplate allows you to pass the list of desired methods you would like the new entity be provided.

For example:

rplate generate my_class -m self.perform perform

will declare the 2 methods in the result entity and spec. To be noted that when ? method wants to be added, it needs to be passed within ''. For example.

rplate generate my_class -m 'valid?'

Root Dir

Sometime you want to place a new entity in a root dir which is not expected to be the root for an another entity. This can be the case for example of app/controllers for a rails application. rplate allows you to pass this root dir via -r option.

Inflections

Sometime you want to place an entity api http_client and you want the result entities to inflect api with API and http with HTTP. rplate allows you to do that with the inflections:

rplate generate api http_client -i api:API http_client:HTTPClient

Enjoy !!!

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/nic-lan/rplate.

License

The gem is available as open source under the terms of the MIT License.

rplate's People

Contributors

dependabot-preview[bot] avatar nic-lan avatar

rplate's Issues

Dependabot can't resolve your Ruby dependency files

Dependabot can't resolve your Ruby dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Bundler::VersionConflict with message: Bundler found conflicting requirements for the Ruby version:
  In Gemfile:
    Ruby (~> 2.3.8.0)

    rplate was resolved to 0.8.0, which depends on
      activesupport (>= 6.1.3.1, <= 6.1.4) was resolved to 6.1.4, which depends on
        Ruby (>= 2.5.0)

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Dependabot can't resolve your Ruby dependency files

Dependabot can't resolve your Ruby dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Bundler::VersionConflict with message: Bundler found conflicting requirements for the Ruby version:
  In Gemfile:
    Ruby (~> 2.3.8.0)

    rplate was resolved to 0.8.0, which depends on
      activesupport (>= 6.1.3.1, <= 6.1.3.2) was resolved to 6.1.3.2, which depends on
        Ruby (>= 2.5.0)

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Dependabot can't resolve your Ruby dependency files

Dependabot can't resolve your Ruby dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Bundler::VersionConflict with message: Bundler found conflicting requirements for the Ruby version:
  In Gemfile:
    Ruby (~> 2.3.8.0)

    rplate was resolved to 0.8.0, which depends on
      activesupport (>= 6.1.3.1, <= 6.1.4) was resolved to 6.1.4, which depends on
        Ruby (>= 2.5.0)

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Epic Rspec Definition

A generated rspec file should include:

  • a describe block for each entity method with:
    • the subject predefined #15
    • a valid example

A generated rspec should not include:

  • a describe block related to the initialize method
  • a duplicate describe block when a method is present as class method and instance method ( e.g. perform and self.perform ). In such a case only the class method should be included.

Change the cli interface

Current Behavior

At the moment the cli accepts the argument entity name as:

rplate generate my_namespace:my_class

or

rplate generate my_namespace/my_class
rplate generate MyNamespace MyClass

just to then translate them into entity constants:

entity_constants = [MyNamespace MyClass]

New Desired Interface

This means to that this translation complexity could be removed or simplified just by enforcing the cli to accept the entity constants as argument like the following:

rplate generate my_namespace my_class

or

rplate generate MyNamespace MyClass

Dependabot can't resolve your Ruby dependency files

Dependabot can't resolve your Ruby dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Bundler::VersionConflict with message: Bundler found conflicting requirements for the Ruby version:
  In Gemfile:
    Ruby (~> 2.3.8.0)

    rplate was resolved to 0.8.0, which depends on
      activesupport (>= 6.0.2, < 6.2.0) was resolved to 6.1.3.2, which depends on
        Ruby (>= 2.5.0)

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Dependabot can't resolve your Ruby dependency files

Dependabot can't resolve your Ruby dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Bundler::VersionConflict with message: Bundler found conflicting requirements for the Ruby version:
  In Gemfile:
    Ruby (~> 2.3.8.0)

    rplate was resolved to 0.8.0, which depends on
      activesupport (>= 6.1.3.1, <= 6.1.3.2) was resolved to 6.1.3.2, which depends on
        Ruby (>= 2.5.0)

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Dependabot can't resolve your Ruby dependency files

Dependabot can't resolve your Ruby dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Bundler::VersionConflict with message: Bundler found conflicting requirements for the Ruby version:
  In Gemfile:
    Ruby (~> 2.3.8.0)

    rplate was resolved to 0.8.0, which depends on
      activesupport (>= 6.1.3.1, <= 6.1.4) was resolved to 6.1.4, which depends on
        Ruby (>= 2.5.0)

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Dependabot can't resolve your Ruby dependency files

Dependabot can't resolve your Ruby dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Bundler::VersionConflict with message: Bundler found conflicting requirements for the Ruby version:
  In Gemfile:
    Ruby (~> 2.3.8.0)

    rplate was resolved to 0.8.0, which depends on
      activesupport (>= 6.0.2, < 6.2.0) was resolved to 6.1.4, which depends on
        Ruby (>= 2.5.0)

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Dependabot can't resolve your Ruby dependency files

Dependabot can't resolve your Ruby dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Bundler::VersionConflict with message: Bundler found conflicting requirements for the Ruby version:
  In Gemfile:
    Ruby (~> 2.3.8.0)

    rplate was resolved to 0.8.0, which depends on
      activesupport (>= 6.0.2, < 6.2.0) was resolved to 6.1.4, which depends on
        Ruby (>= 2.5.0)

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Dependabot can't resolve your Ruby dependency files

Dependabot can't resolve your Ruby dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Bundler::VersionConflict with message: Bundler found conflicting requirements for the Ruby version:
  In Gemfile:
    Ruby (~> 2.3.8.0)

    rplate was resolved to 0.8.0, which depends on
      activesupport (>= 6.1.3.1, <= 6.1.3.2) was resolved to 6.1.3.2, which depends on
        Ruby (>= 2.5.0)

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Improve Entity Naming

Ensure that:

  • a name like my_module/my_class would define the entity MyModule::MyClass
  • a name like 2MyClass should raise invalid
  • a name with empty spaces should not be allowed ( e.g. My Module )
  • a name like RPlate should be able to inflect into rplate when that is the configuration and not into r_plate
  • it should be possible to overwrite an existing entity only after confirmation

Smart Namespacing

The generate command should smart enough to understand when the namespace scoped of a desired entity are class or module.

rplate generate MyNamespace::MyEntity

This should result in:

  • MyNamespace is module as default case scenario
  • MyNamespace is class in the case MyNamespace is a constant already defined as class
  • MyNamespace is module in the case MyNamespace is a constant already defined as module

Configurable Rubocop

It should be possible to run rubocop based on:

  • a .rubocop.yml file that is present in the current directory where the rplate is launched
  • rubocop file path passed as argument to the generate command

Dependabot can't resolve your Ruby dependency files

Dependabot can't resolve your Ruby dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Bundler::VersionConflict with message: Bundler found conflicting requirements for the Ruby version:
  In Gemfile:
    Ruby (~> 2.3.8.0)

    rplate was resolved to 0.8.0, which depends on
      activesupport (>= 6.0.2, < 6.2.0) was resolved to 6.1.3.2, which depends on
        Ruby (>= 2.5.0)

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Dependabot can't resolve your Ruby dependency files

Dependabot can't resolve your Ruby dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Bundler::VersionConflict with message: Bundler found conflicting requirements for the Ruby version:
  In Gemfile:
    Ruby (~> 2.3.8.0)

    rplate was resolved to 0.8.0, which depends on
      activesupport (>= 6.0.2, < 6.2.0) was resolved to 6.1.3.1, which depends on
        Ruby (>= 2.5.0)

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Apply Standard Thor Pattern Or move to Clamp/Dry-CLI

Currently Thor is the support gem for the cli but it is not entirely used how it should be.

Investigate when to :

  • Generate Command should become a subcommand and we could take advantage of including in it the Thor::Actions
  • Thor is an all comprehnsive tool. better something less ? better Clamp ?

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.