Class: LucidWorks::DatasourceType

Inherits:
Object
  • Object
show all
Defined in:
lib/lucid_works/datasource_type.rb

Constant Summary collapse

DONT_INITIALIZE_PROPERTIES =
[
  "collection",  # not something we can provide a default for
  "name",        # not something we can provide a default for
  "---"          # Separator UI hint
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(crawler, attributes = {}) ⇒ DatasourceType

Returns a new instance of DatasourceType.



13
14
15
16
17
18
# File 'lib/lucid_works/datasource_type.rb', line 13

def initialize(crawler, attributes = {})
  @crawler  = crawler
  @category = attributes['category']
  @type     = attributes['type']
  @props    = attributes['props']
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



11
12
13
# File 'lib/lucid_works/datasource_type.rb', line 11

def category
  @category
end

#crawlerObject (readonly)

Returns the value of attribute crawler.



11
12
13
# File 'lib/lucid_works/datasource_type.rb', line 11

def crawler
  @crawler
end

#propsObject (readonly)

Returns the value of attribute props.



11
12
13
# File 'lib/lucid_works/datasource_type.rb', line 11

def props
  @props
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/lucid_works/datasource_type.rb', line 11

def type
  @type
end

Instance Method Details

#default_attributesObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lucid_works/datasource_type.rb', line 30

def default_attributes
  attrs = {}.with_indifferent_access
  properties.inject(attrs) do |hash, property|
    unless DONT_INITIALIZE_PROPERTIES.include?(property.name) || property.read_only?
      hash[property.name] = property.default_value
    end
    hash
  end
  attrs.merge!(
    :crawler => @crawler.name,
    :type => @type
  )
end

#propertiesObject



20
21
22
23
24
# File 'lib/lucid_works/datasource_type.rb', line 20

def properties
  @properties ||= @props.map do |prop|
    DatasourceProperty.new(prop)
  end
end

#property(name) ⇒ Object



26
27
28
# File 'lib/lucid_works/datasource_type.rb', line 26

def property(name)
  properties.detect { |p| p.name == name }
end