Class: ApiSerializer::AttributeOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/api_serializer/attribute_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute_reflection, from_path:, composed_of:, decompose_to:, convert_by:, virtual:, queryable: nil, nested_schema: nil) ⇒ AttributeOptions

Returns a new instance of AttributeOptions.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/api_serializer/attribute_options.rb', line 3

def initialize(attribute_reflection, from_path:, composed_of:, decompose_to:, convert_by:, virtual:, queryable: nil, nested_schema: nil)
  @attribute_reflection = attribute_reflection
  @from_path = from_path
  @composed_of = composed_of
  @decompose_to = decompose_to
  @convert_by = convert_by
  @virtual = virtual
  @nested_schema = nested_schema

  config = queryable ? normalize_queryable(queryable) : QueryableConfig.new(filter: false, sort: false)
  @filterable = config.filterable?
  @sortable = config.sortable?
  @query_column = config.column
  @query_transform = config.transform
  @allowed_values = config.allowed_values
end

Instance Attribute Details

#allowed_valuesObject (readonly)

Returns the value of attribute allowed_values.



27
28
29
# File 'lib/api_serializer/attribute_options.rb', line 27

def allowed_values
  @allowed_values
end

#composed_ofObject (readonly)

Returns the value of attribute composed_of.



27
28
29
# File 'lib/api_serializer/attribute_options.rb', line 27

def composed_of
  @composed_of
end

#convert_byObject (readonly)

Returns the value of attribute convert_by.



27
28
29
# File 'lib/api_serializer/attribute_options.rb', line 27

def convert_by
  @convert_by
end

#decompose_toObject (readonly)

Returns the value of attribute decompose_to.



27
28
29
# File 'lib/api_serializer/attribute_options.rb', line 27

def decompose_to
  @decompose_to
end

#from_pathObject (readonly)

Returns the value of attribute from_path.



27
28
29
# File 'lib/api_serializer/attribute_options.rb', line 27

def from_path
  @from_path
end

#nested_schemaObject (readonly)

Returns the value of attribute nested_schema.



27
28
29
# File 'lib/api_serializer/attribute_options.rb', line 27

def nested_schema
  @nested_schema
end

#query_columnObject (readonly)

Returns the value of attribute query_column.



27
28
29
# File 'lib/api_serializer/attribute_options.rb', line 27

def query_column
  @query_column
end

#query_transformObject (readonly)

Returns the value of attribute query_transform.



27
28
29
# File 'lib/api_serializer/attribute_options.rb', line 27

def query_transform
  @query_transform
end

#virtualObject (readonly)

Returns the value of attribute virtual.



27
28
29
# File 'lib/api_serializer/attribute_options.rb', line 27

def virtual
  @virtual
end

Instance Method Details

#association?Boolean

Returns:

  • (Boolean)


35
# File 'lib/api_serializer/attribute_options.rb', line 35

def association? = !!@nested_schema

#coercionObject



25
# File 'lib/api_serializer/attribute_options.rb', line 25

def coercion = @attribute_reflection.coercion

#compose?Boolean

Returns:

  • (Boolean)


30
# File 'lib/api_serializer/attribute_options.rb', line 30

def compose? = !!composed_of

#decompose?Boolean

Returns:

  • (Boolean)


31
# File 'lib/api_serializer/attribute_options.rb', line 31

def decompose? = !!decompose_to

#defaultObject



24
# File 'lib/api_serializer/attribute_options.rb', line 24

def default = @attribute_reflection.default

#filterable?Boolean

Returns:

  • (Boolean)


33
# File 'lib/api_serializer/attribute_options.rb', line 33

def filterable? = !!@filterable

#nameObject



20
# File 'lib/api_serializer/attribute_options.rb', line 20

def name = @attribute_reflection.name

#positionalObject



23
# File 'lib/api_serializer/attribute_options.rb', line 23

def positional = @attribute_reflection.positional

#readerObject



22
# File 'lib/api_serializer/attribute_options.rb', line 22

def reader = @attribute_reflection.reader

#sortable?Boolean

Returns:

  • (Boolean)


34
# File 'lib/api_serializer/attribute_options.rb', line 34

def sortable? = !!@sortable

#to_hObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/api_serializer/attribute_options.rb', line 37

def to_h
  {
    name:, type:, reader:, positional:, default:,
    composed_of:, decompose_to:, convert_by:, from_path:, virtual:,
    filterable: @filterable,
    sortable: @sortable,
    query_column: @query_column,
    query_transform: @query_transform,
    allowed_values: @allowed_values,
    nested_schema: @nested_schema
  }
end

#typeObject



21
# File 'lib/api_serializer/attribute_options.rb', line 21

def type = @attribute_reflection.type

#virtual?Boolean

Returns:

  • (Boolean)


32
# File 'lib/api_serializer/attribute_options.rb', line 32

def virtual? = !!virtual