Class: Blueprinter::View Private

Inherits:
Object
  • Object
show all
Defined in:
lib/blueprinter/view.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

Instance Method Summary collapse

Constructor Details

#initialize(name, fields: {}, included_view_names: [], excluded_view_names: []) ⇒ 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.



6
7
8
9
10
11
# File 'lib/blueprinter/view.rb', line 6

def initialize(name, fields: {}, included_view_names: [], excluded_view_names: [])
  @name = name
  @fields = fields
  @included_view_names = included_view_names
  @excluded_field_names = excluded_view_names
end

Instance Attribute Details

#excluded_field_namesObject (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.rb', line 4

def excluded_field_names
  @excluded_field_names
end

#fieldsObject (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.rb', line 4

def fields
  @fields
end

#included_view_namesObject (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.rb', line 4

def included_view_names
  @included_view_names
end

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



4
5
6
# File 'lib/blueprinter/view.rb', line 4

def name
  @name
end

Instance Method Details

#<<(field) ⇒ 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.



41
42
43
# File 'lib/blueprinter/view.rb', line 41

def <<(field)
  fields[field.name] = field
end

#exclude_field(field_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.



31
32
33
# File 'lib/blueprinter/view.rb', line 31

def exclude_field(field_name)
  excluded_field_names << field_name
end

#exclude_fields(field_names) ⇒ 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.



35
36
37
38
39
# File 'lib/blueprinter/view.rb', line 35

def exclude_fields(field_names)
  field_names.each do |field_name|
    excluded_field_names << field_name
  end
end

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



27
28
29
# File 'lib/blueprinter/view.rb', line 27

def include_view(view_name)
  included_view_names << view_name
end

#inherit(view) ⇒ 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
18
19
20
21
22
23
24
25
# File 'lib/blueprinter/view.rb', line 13

def inherit(view)
  view.fields.values.each do |field|
    self << field
  end

  view.included_view_names.each do |view_name|
    include_view(view_name)
  end

  view.excluded_field_names.each do |field_name|
    exclude_field(field_name)
  end
end