Class: Blueprinter::ViewCollection Private
- Inherits:
-
Object
- Object
- Blueprinter::ViewCollection
- Defined in:
- lib/blueprinter/view_collection.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #sort_by_definition ⇒ Object readonly private
- #views ⇒ Object readonly private
Instance Method Summary collapse
- #[](view_name) ⇒ Object private
- #fields_for(view_name) ⇒ Object private
- #inherit(view_collection) ⇒ Object private
-
#initialize ⇒ ViewCollection
constructor
private
A new instance of ViewCollection.
- #transformers(view_name) ⇒ Object private
- #view?(view_name) ⇒ Boolean private
Constructor Details
#initialize ⇒ ViewCollection
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ViewCollection.
10 11 12 13 14 15 16 |
# File 'lib/blueprinter/view_collection.rb', line 10 def initialize @views = { identifier: View.new(:identifier), default: View.new(:default) } @sort_by_definition = Blueprinter.configuration.sort_fields_by.eql?(:definition) end |
Instance Attribute Details
#sort_by_definition ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/blueprinter/view_collection.rb', line 8 def sort_by_definition @sort_by_definition end |
#views ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/blueprinter/view_collection.rb', line 8 def views @views end |
Instance Method Details
#[](view_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 |
# File 'lib/blueprinter/view_collection.rb', line 45 def [](view_name) @views[view_name] ||= View.new(view_name) end |
#fields_for(view_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/blueprinter/view_collection.rb', line 28 def fields_for(view_name) return identifier_fields if view_name == :identifier fields, excluded_fields = sortable_fields(view_name) sorted_fields = sort_by_definition ? sort_by_def(view_name, fields) : fields.values.sort_by(&:name) (identifier_fields + sorted_fields).tap do |fields_array| fields_array.reject! { |field| excluded_fields.include?(field.name) } end end |
#inherit(view_collection) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
18 19 20 21 22 |
# File 'lib/blueprinter/view_collection.rb', line 18 def inherit(view_collection) view_collection.views.each do |view_name, view| self[view_name].inherit(view) end end |
#transformers(view_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 42 43 |
# File 'lib/blueprinter/view_collection.rb', line 39 def transformers(view_name) included_transformers = gather_transformers_from_included_views(view_name).reverse all_transformers = [*views[:default].view_transformers, *included_transformers].uniq all_transformers.empty? ? Blueprinter.configuration.default_transformers : all_transformers end |
#view?(view_name) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
24 25 26 |
# File 'lib/blueprinter/view_collection.rb', line 24 def view?(view_name) views.key? view_name end |