Class: Interactors::Api::RepresentEventsJson

Inherits:
Object
  • Object
show all
Includes:
Interpipe::Interactor
Defined in:
app/interactors/api/represent_events_json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Interpipe::Interactor

included, #initialize, #setup

Instance Attribute Details

#compoundsObject (readonly)

Returns the value of attribute compounds


11
12
13
# File 'app/interactors/api/represent_events_json.rb', line 11

def compounds
  @compounds
end

#eventsObject (readonly)

Returns the value of attribute events


11
12
13
# File 'app/interactors/api/represent_events_json.rb', line 11

def events
  @events
end

#metaObject (readonly)

Returns the value of attribute meta


11
12
13
# File 'app/interactors/api/represent_events_json.rb', line 11

def meta
  @meta
end

#representerObject (readonly)

Returns the value of attribute representer


11
12
13
# File 'app/interactors/api/represent_events_json.rb', line 11

def representer
  @representer
end

Instance Method Details

#perform(events:, params:, include_student_ids: true) ⇒ Object


13
14
15
16
17
18
19
20
21
# File 'app/interactors/api/represent_events_json.rb', line 13

def perform(events:, params:, include_student_ids: true)
  paginated = Paginate.perform(dataset: events, params: params)
  @meta = paginated.meta
  @events = paginated.dataset

  @include_student_ids = include_student_ids
  @compounds = CompoundEvents.perform(events: @events, params: params).compounds
  @representer = EventsRepresenter.for_collection.prepare(@events.eager(:parallel).all)
end

#to_hash(options = {}) ⇒ Object


23
24
25
26
27
28
29
30
31
# File 'app/interactors/api/represent_events_json.rb', line 23

def to_hash(options = {})
  representer.to_hash({
    include_student_ids: @include_student_ids,
    courses: compounds[:courses].to_a,
    teachers: compounds[:teachers].to_a,
    schedule_exceptions: compounds[:schedule_exceptions].to_a,
    'meta' => meta
  })
end