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
]
SYSTEM_TYPES =
%w{ lucidworkslogs }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of DatasourceType.



15
16
17
18
19
20
# File 'lib/lucid_works/datasource_type.rb', line 15

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.



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

def category
  @category
end

#crawlerObject (readonly)

Returns the value of attribute crawler.



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

def crawler
  @crawler
end

#propsObject (readonly)

Returns the value of attribute props.



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

def props
  @props
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#default_attributesObject



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/lucid_works/datasource_type.rb', line 44

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



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/lucid_works/datasource_type.rb', line 26

def properties
  @properties ||= @props.map do |prop|
    DatasourceProperty.new(prop)
  end.tap do |properties|
    def properties.regular
      select {|p| !p.advanced? }
    end

    def properties.advanced
      select &:advanced?
    end
  end
end

#property(name) ⇒ Object



40
41
42
# File 'lib/lucid_works/datasource_type.rb', line 40

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

#system?Boolean

Returns:

  • (Boolean)


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

def system?
  SYSTEM_TYPES.include? type
end