Ticket #32 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

Change D() to allow :urls override.

Reported by: zimbatm Owned by: why
Priority: major Milestone: Camping 1.5
Component: bin/camping Version: 1.4.2
Keywords: Cc:

Description

class R; include Base; end

That class is used when you build a new controller with that magic R() method.

Base is not needed since it is included dynamically Camping::Controller::D(). Also, classes issued by R should not be different that normal classes I think.

Removing the dependency on R has two advantages :

  • Around 9 bytes are gained
  • R() could now depend on other classes and support class inheritance

I've made some tests and everything seems to work however I might miss some point.

You'll find the patch for camping-unabridged.rb and a test app below. Maybe I should also provide the patch for camping.rb ?

Attachments

eight_bytes.diff (1.3 kB) - added by zimbatm 2 years ago.
Removing R patch
testing.rb (1.0 kB) - added by zimbatm 2 years ago.
Testing app
nor.diff (1.4 kB) - added by zimbatm 2 years ago.
Replaced if(!k<R) with unless k.respond_to?(:urls)

Change History

Changed 2 years ago by zimbatm

Removing R patch

Changed 2 years ago by zimbatm

Testing app

Changed 2 years ago by zimbatm

By the way this patch would also be highly useful for the scaffolding code I'm writing.

The scaffolding controller sets it's own urls from a root url. It looks something like that :

class Scaffolder
  class << self
    attr_accessor :path
    def urls; %w[list add remove].map{|x| "#{path}/#{x}"}; end
  end
  # other stuff here
end

Right now, Scaffolder#urls gets rewritten (in D()) because Scaffolder doesn't inherit R. But I can't inherit R because it's a different class in every application.

Changed 2 years ago by why

  • status changed from new to assigned
  • version set to 1.4.2
  • milestone set to Camping 1.5

The real issue is that urls is getting overwritten. I'm okay changing the D() method to accomodate, but I'm not ready to get rid of the R class.

Changed 2 years ago by zimbatm

I agree that that D() is the main problem but but do you see any other uses of the R class ? I fear that R() issued Controllers won't have the same capabilities than the non-R() issued ones.

And like I said R() could also be adapted to inherit from other classes (like a Scaffold class). Naturally D() is the main problem and I can live without the rest ;-)

Changed 2 years ago by zimbatm

Replaced if(!k<R) with unless k.respond_to?(:urls)

Changed 2 years ago by why

  • summary changed from R class not needed ~9 bytes won to Change D() to allow :urls override.

Changed 2 years ago by why

  • status changed from assigned to closed
  • resolution set to fixed

I changed my mind and went with your complete patch. See [119]. Thanks for hanging in there!

Note: See TracTickets for help on using tickets.