Skip to content

How to subclass and add functionality to Bridgetown::Resource::Base? #676

Answered by jaredcwhite
joemasilotti asked this question in Q&A
Discussion options

You must be logged in to vote

So there's not really a concept of a Resource subclass. If you were using a Model subclass, you could get at that via resource.model.some_method. But there's a way to define resource extensions:

https://edge.bridgetownrb.com/docs/plugins/resource-extensions (1.2 docs)

That applies to any type of resource, so if you want different behavior depending on collection you'd handle that within the method.

Otherwise, at the model level, you could do:

class Post < Bridgetown::Model::Base
  def foo
    "Hi!"
  end
end

# later:
post_resource.model.foo

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@joemasilotti
Comment options

@jaredcwhite
Comment options

@joemasilotti
Comment options

@jaredcwhite
Comment options

@joemasilotti
Comment options

Answer selected by joemasilotti
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants