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
- #has_view?(view_name) ⇒ Boolean private
- #inherit(view_collection) ⇒ Object private
-
#initialize ⇒ ViewCollection
constructor
private
A new instance of ViewCollection.
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.
5 6 7 8 9 10 11 |
# File 'lib/blueprinter/view_collection.rb', line 5 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.
4 5 6 |
# File 'lib/blueprinter/view_collection.rb', line 4 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.
4 5 6 |
# File 'lib/blueprinter/view_collection.rb', line 4 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.
29 30 31 |
# File 'lib/blueprinter/view_collection.rb', line 29 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.
23 24 25 26 27 |
# File 'lib/blueprinter/view_collection.rb', line 23 def fields_for(view_name) fields = sortable_fields(view_name).values sorted_fields = sort_by_definition ? fields : fields.sort_by(&:name) identifier_fields + sorted_fields end |
#has_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.
19 20 21 |
# File 'lib/blueprinter/view_collection.rb', line 19 def has_view?(view_name) views.has_key? view_name 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.
13 14 15 16 17 |
# File 'lib/blueprinter/view_collection.rb', line 13 def inherit(view_collection) view_collection.views.each do |view_name, view| self[view_name].inherit(view) end end |