Class: ModelSerializer

Inherits:
ApplicationSerializer show all
Defined in:
app/serializers/model_serializer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationSerializer

#to_json

Constructor Details

#initialize(model:, macro:, parent: nil) ⇒ ModelSerializer

Returns a new instance of ModelSerializer.



6
7
8
9
10
# File 'app/serializers/model_serializer.rb', line 6

def initialize(model:, macro:, parent: nil)
  @model = model
  @macro = macro
  @parent = parent
end

Instance Attribute Details

#macroObject (readonly)

Returns the value of attribute macro.



4
5
6
# File 'app/serializers/model_serializer.rb', line 4

def macro
  @macro
end

#modelObject (readonly)

Returns the value of attribute model.



4
5
6
# File 'app/serializers/model_serializer.rb', line 4

def model
  @model
end

#parentObject (readonly)

Returns the value of attribute parent.



4
5
6
# File 'app/serializers/model_serializer.rb', line 4

def parent
  @parent
end

Instance Method Details

#to_hObject



12
13
14
15
16
17
18
19
# File 'app/serializers/model_serializer.rb', line 12

def to_h
  {
    model: model.name,
    columns: model.column_names,
    scopes: build_scopes,
    associations: build_associations
  }
end