Class: Oaken::Loader::Type

Inherits:
Struct
  • Object
show all
Defined in:
lib/oaken/loader/type.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#gsubObject

Returns the value of attribute gsub

Returns:

  • (Object)

    the current value of gsub



3
4
5
# File 'lib/oaken/loader/type.rb', line 3

def gsub
  @gsub
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



3
4
5
# File 'lib/oaken/loader/type.rb', line 3

def name
  @name
end

Class Method Details

.for(name) ⇒ Object



5
# File 'lib/oaken/loader/type.rb', line 5

def self.for(name) = new(name, name.classify.gsub(/(?<=[a-z])(?=[A-Z])/))

.locate(name) ⇒ Object



4
# File 'lib/oaken/loader/type.rb', line 4

def self.locate(name) = self.for(name.to_s).locate

Instance Method Details

#locateObject



7
8
9
# File 'lib/oaken/loader/type.rb', line 7

def locate
  possible_consts.filter_map(&:safe_constantize).first
end

#possible_constsObject



11
12
13
14
15
# File 'lib/oaken/loader/type.rb', line 11

def possible_consts
  separator_matrixes.fetch(gsub.count).map { |seps| gsub.with_index { seps[_2] } }
rescue KeyError
  raise ArgumentError, "can't resolve #{name} to an object, please call register manually"
end