-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's not really doing much, just add the bits that are used ourselves
- Loading branch information
Showing
5 changed files
with
46 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationDecorator < Draper::Decorator | ||
def self.inherited(child_class) | ||
class ApplicationDecorator | ||
include ActiveModel::Serialization | ||
include ActiveModel::Serializers::JSON | ||
|
||
# Delegate columns and instance methods | ||
def self.inherited(decorator_class) | ||
super | ||
child_class.class_eval do | ||
def self.collection_decorator_class | ||
PaginatedDecorator | ||
end | ||
model_class = decorator_class.name.delete_suffix("Decorator").constantize | ||
decorator_class.class_eval do | ||
delegate *model_class.column_names, *model_class.instance_methods(false), to: :@object # rubocop:disable Lint/AmbiguousOperator | ||
end | ||
end | ||
|
||
delegate_all | ||
delegate_missing_to :@object | ||
delegate :to_param, :to_partial_path, to: :@object | ||
|
||
attr_reader :helpers | ||
alias h helpers | ||
|
||
def initialize(object) | ||
@object = object | ||
@helpers = ApplicationController.helpers | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class PaginatedDecorator < Draper::CollectionDecorator | ||
delegate :current_page, :total_pages, :limit_value, :entry_name, :total_count, :offset_value, :last_page? | ||
class PaginatedDecorator | ||
delegate :current_page, :total_pages, :limit_value, :entry_name, :total_count, :offset_value, :last_page?, to: :@object | ||
delegate *Array.instance_methods(false), to: :collection # rubocop:disable Lint/AmbiguousOperator | ||
|
||
def initialize(object) | ||
@object = object | ||
end | ||
|
||
def collection | ||
@collection ||= @object.map(&:decorate) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters