Class: Zobi::Discover

Inherits:
Struct
  • Object
show all
Defined in:
lib/zobi/discover.rb

Constant Summary collapse

CONFIG =
{
  decorated: {
    suffix: 'Decorator',
    resource: 'ResourceDecorator',
    collection: 'CollectionDecorator'
  }
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#behaviorObject

Returns the value of attribute behavior

Returns:

  • (Object)

    the current value of behavior



4
5
6
# File 'lib/zobi/discover.rb', line 4

def behavior
  @behavior
end

#klassObject

Returns the value of attribute klass

Returns:

  • (Object)

    the current value of klass



4
5
6
# File 'lib/zobi/discover.rb', line 4

def klass
  @klass
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



4
5
6
# File 'lib/zobi/discover.rb', line 4

def type
  @type
end

Class Method Details

.classes_for_namespaces(namespaces, base_name) ⇒ Object



63
64
65
66
67
# File 'lib/zobi/discover.rb', line 63

def classes_for_namespaces namespaces, base_name
  namespaces.map{|ns|
    "#{ns == '::' ? ns : "#{ns}::"}#{base_name}"
  }
end

Instance Method Details

#resolveObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/zobi/discover.rb', line 13

def resolve
  discovery.each do |klass|
    begin
      return klass.constantize
    rescue NameError
      next
    end
  end
  "Zobi::#{fallback}".constantize
end