Class: LcpRuby::DataSource::Host

Inherits:
Base
  • Object
show all
Defined in:
lib/lcp_ruby/data_source/host.rb

Overview

Host adapter data source. Delegates to a host-app-provided class that implements the DataSource::Base contract.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#destroy, #save, #writable?

Constructor Details

#initialize(config, model_definition) ⇒ Host

Returns a new instance of Host.

Raises:



8
9
10
11
12
13
14
15
16
17
# File 'lib/lcp_ruby/data_source/host.rb', line 8

def initialize(config, model_definition)
  provider_class_name = config["provider"]
  raise MetadataError, "Host data source requires 'provider' class name" unless provider_class_name

  @provider = provider_class_name.constantize.new
  @config = config
  @model_definition = model_definition

  validate_provider!
end

Instance Attribute Details

#providerObject (readonly)

Returns the value of attribute provider.



6
7
8
# File 'lib/lcp_ruby/data_source/host.rb', line 6

def provider
  @provider
end

Instance Method Details

#count(params = {}) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/lcp_ruby/data_source/host.rb', line 35

def count(params = {})
  if @provider.respond_to?(:count)
    @provider.count(params)
  else
    super
  end
end

#find(id) ⇒ Object



19
20
21
# File 'lib/lcp_ruby/data_source/host.rb', line 19

def find(id)
  @provider.find(id)
end

#find_many(ids) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/lcp_ruby/data_source/host.rb', line 23

def find_many(ids)
  if @provider.respond_to?(:find_many)
    @provider.find_many(ids)
  else
    super
  end
end

#search(params = {}, sort: nil, page: 1, per: 25) ⇒ Object



31
32
33
# File 'lib/lcp_ruby/data_source/host.rb', line 31

def search(params = {}, sort: nil, page: 1, per: 25)
  @provider.search(params, sort: sort, page: page, per: per)
end

#select_options(search: nil, filter: {}, sort: nil, label_method: "to_label", limit: 200) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/lcp_ruby/data_source/host.rb', line 43

def select_options(search: nil, filter: {}, sort: nil, label_method: "to_label", limit: 200)
  if @provider.respond_to?(:select_options)
    @provider.select_options(search: search, filter: filter, sort: sort, label_method: label_method, limit: limit)
  else
    super
  end
end

#supported_operatorsObject



51
52
53
54
55
56
57
# File 'lib/lcp_ruby/data_source/host.rb', line 51

def supported_operators
  if @provider.respond_to?(:supported_operators)
    @provider.supported_operators
  else
    super
  end
end