Class: SalsaLabs::ObjectsFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/salsa_labs/objects_fetcher.rb

Overview

Service object that fetches a collection of objects from API and returns them as instances of a specified class

Defined Under Namespace

Classes: SalsaLabsApiObjectNode

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ ObjectsFetcher

Returns a new instance of ObjectsFetcher.



16
17
18
19
20
21
# File 'lib/salsa_labs/objects_fetcher.rb', line 16

def initialize(opts = {})
  @filters = opts[:filters]
  @client = opts[:client]
  @type = opts[:type]
  @item_class = opts[:item_class]
end

Class Method Details

.fetch(opts = {}) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/salsa_labs/objects_fetcher.rb', line 7

def self.fetch(opts = {})
  filters = opts[:filters] || {}
  credentials = opts[:credentials] || {}
  client = SalsaLabs::ApiClient.new(credentials)
  type = opts.fetch(:type)
  item_class = opts[:item_class] || SalsaLabs::SalsaObject
  new(filters: filters, client: client, type: type, item_class: item_class).fetch
end

Instance Method Details

#fetchObject



23
24
25
26
27
# File 'lib/salsa_labs/objects_fetcher.rb', line 23

def fetch
  item_nodes.map do |node|
    item_class.new(SalsaLabsApiObjectNode.new(node).attributes)
  end
end