Class: Blueprinter::Reflection::View Private

Inherits:
Object
  • Object
show all
Defined in:
lib/blueprinter/reflection.rb

Overview

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.

Represents a view within a Blueprint.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, view_collection) ⇒ View

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 View.



37
38
39
40
# File 'lib/blueprinter/reflection.rb', line 37

def initialize(name, view_collection)
  @name = name
  @view_collection = view_collection
end

Instance Attribute Details

#nameObject (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.



35
36
37
# File 'lib/blueprinter/reflection.rb', line 35

def name
  @name
end

Instance Method Details

#associationsHash<Symbol, Blueprinter::Reflection::Association>

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 Hash of associations in this view (recursive) keyed by method name.

Returns:



60
61
62
63
64
65
66
67
68
# File 'lib/blueprinter/reflection.rb', line 60

def associations
  @associations ||= @view_collection.fields_for(name).each_with_object({}) do |field, obj|
    next unless field.options[:association]

    blueprint = field.options.fetch(:blueprint)
    view = field.options[:view] || :default
    obj[field.name] = Association.new(field.method, field.name, blueprint, view, field.options)
  end
end

#fieldsHash<Symbol, Blueprinter::Reflection::Field>

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 Hash of fields in this view (recursive) keyed by method name.

Returns:



47
48
49
50
51
52
53
# File 'lib/blueprinter/reflection.rb', line 47

def fields
  @fields ||= @view_collection.fields_for(name).each_with_object({}) do |field, obj|
    next if field.options[:association]

    obj[field.name] = Field.new(field.method, field.name, field.options)
  end
end