Class: UiHelper::Summary

Inherits:
Object
  • Object
show all
Defined in:
app/models/ui_helper/summary.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Summary

Returns a new instance of Summary.



10
11
12
13
14
# File 'app/models/ui_helper/summary.rb', line 10

def initialize(options = {})
  @summary_items = []
  @current_page = options[:page].to_i || 1
  @item_per_page = options[:per_page].to_i || 10
end

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page.



8
9
10
# File 'app/models/ui_helper/summary.rb', line 8

def current_page
  @current_page
end

#summary_itemsObject

Returns the value of attribute summary_items.



8
9
10
# File 'app/models/ui_helper/summary.rb', line 8

def summary_items
  @summary_items
end

Instance Method Details

#add(item) ⇒ Object



64
65
66
# File 'app/models/ui_helper/summary.rb', line 64

def add(item)
  @summary_items << item
end

#load(study) ⇒ Object



16
17
18
19
20
21
22
# File 'app/models/ui_helper/summary.rb', line 16

def load(study)
  study.submissions.each do |submission|
    submission.events.where('message LIKE "Run%"').find_each { |event| load_event(event) }
  end
  load_study(study)
  summaries
end

#load_asset(asset) ⇒ Object



26
27
28
# File 'app/models/ui_helper/summary.rb', line 26

def load_asset(asset)
  asset.events_on_requests.where('message LIKE "Run%"').find_each { |event| load_event(event) }
end

#load_event(event) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/ui_helper/summary.rb', line 34

def load_event(event)
  add(
    SummaryItem.new(
      message: event.message,
      object: event.eventful,
      timestamp: event.created_at,
      external_message: "Run #{event.identifier}",
      external_link: "#{configatron.run_information_url}#{event.identifier}"
    )
  )
end

#load_request(request) ⇒ Object



30
31
32
# File 'app/models/ui_helper/summary.rb', line 30

def load_request(request)
  request.run_events.each { |event| load_event(event) }
end

#load_study(study) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/ui_helper/summary.rb', line 46

def load_study(study)
  study.events.find_each do |event|
    add(
      SummaryItem.new(
        message: event.message,
        object: study,
        timestamp: event.created_at,
        external_message: "Study #{study.id}",
        external_link: ''
      )
    )
  end
end

#sizeObject



68
69
70
# File 'app/models/ui_helper/summary.rb', line 68

def size
  @summary_items.size
end

#summariesObject



60
61
62
# File 'app/models/ui_helper/summary.rb', line 60

def summaries
  summary_items.sort_by(&:timestamp).reverse
end