Skip to content

Commit

Permalink
Extract method to build a data source
Browse files Browse the repository at this point in the history
  • Loading branch information
javierm authored and taitus committed Jun 20, 2024
1 parent 7a0677b commit ebbd818
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 7 additions & 9 deletions app/models/ahoy/chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@ def self.event_names_with_collections
end

def self.active_events_data_points
ds = Ahoy::DataSource.new

active_event_names.map { |event_name| new(event_name) }.each do |chart|
ds.add chart.title, chart.data
Ahoy::DataSource.build do |data_source|
active_event_names.map { |event_name| new(event_name) }.each do |chart|
data_source.add chart.title, chart.data
end
end

ds.build
end

def data_points
ds = Ahoy::DataSource.new
ds.add title, data
ds.build
Ahoy::DataSource.build do |data_source|
data_source.add title, data
end
end

def title
Expand Down
4 changes: 4 additions & 0 deletions app/models/ahoy/data_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

module Ahoy
class DataSource
def self.build(&block)
new.tap { |data_source| block.call(data_source) }.build
end

# Adds a collection with the datasource
# Name is the name of the collection and will be showed in the
# chart
Expand Down

0 comments on commit ebbd818

Please sign in to comment.