Giter VIP home page Giter VIP logo

Comments (7)

PikachuEXE avatar PikachuEXE commented on June 12, 2024 1

Might as well make it accept options like dry-types:
https://dry-rb.org/gems/dry-types/1.2/getting-started/

  include OopsARake::Task(
    name: "custom_name",
  )

Their implementation looks like:
https://github.com/dry-rb/dry-types/blob/v1.4.0/lib/dry/types.rb#L201-L203

from oops_a_rake.

odlp avatar odlp commented on June 12, 2024 1

I've just released version 0.2.0 which supports custom task names. Thanks for the suggestion & feedback @PikachuEXE

from oops_a_rake.

odlp avatar odlp commented on June 12, 2024

Hi @PikachuEXE,

I like this suggestion, it makes a lot of sense.

Unfortunately adding this feature is quite complicated under the current implementation. At the moment the task is registered immediately when the OopsARake::Task module is included:

def self.included(klass)
Registry::register(klass)
klass.extend(ClassMethods)
end

Originally I thought we could just rename the Rake task if #name is called, but Rake doesn't seem to have a public API for renaming tasks (it seems possible by accessing instance variables, but I'd rather avoid that).

To support this feature I think we'd have to defer registration of Rake tasks until a hook is called, similar to this in the Rakefile:

# Rakefile

require "oops_a_rake"

# Optional config
OopsARake.task_paths = ["lib/tasks/*.rb"]

OopsARake.load_tasks

I think this more explicit loading mechanism is probably a better design, similar to FactoryBot.find_definitions.

I can take a look at adding this over the weekend. Ay feedback on the proposed changes would be welcome!

from oops_a_rake.

PikachuEXE avatar PikachuEXE commented on June 12, 2024

Or something like this (but not sure if can be done):

class GreetingTask
  include OopsARake::Task::Lazy

  register do |task|
    #not calling `name` = generate name from class
    task.name "say_hello"
    task.description "An enthusiastic greeting"
    # other config
  end

  def call
    puts "Hello!"
  end
end

from oops_a_rake.

odlp avatar odlp commented on June 12, 2024

@PikachuEXE I've made a PR proposing a solution like this:

class ObscureClassNameTask do
  include OopsARake::Task.with_name("custom_name")
  
  def call
    puts "Hello"
  end
end

Would this work for you?

from oops_a_rake.

odlp avatar odlp commented on June 12, 2024

I don't think that'll work in this case unless I'm missing something. Mimicking the self.Types method from dry-types would mean that'd including the module would be include OopsARake.Task rather than include OopsARake::Task, which seems weird to me.

My preference would be to not compromise the base use case to support this feature. I'd suggest a halfway house which is more flexible than ::with_name for future use cases:

include OopsARake::Task.with_options(name: "custom_name")

from oops_a_rake.

PikachuEXE avatar PikachuEXE commented on June 12, 2024

As long as it's flexible enough I am fine with it

from oops_a_rake.

Related Issues (1)

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.