Class: Motoko::Resolvers::BaseResolver

Inherits:
Object
  • Object
show all
Includes:
Utils::SnakeToCamel
Defined in:
lib/motoko/resolvers/base_resolver.rb

Direct Known Subclasses

Cpu, Fact, Identity, Os, RebootRequired

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::SnakeToCamel

#snake_to_camel_case

Constructor Details

#initialize(name, options) ⇒ BaseResolver

Returns a new instance of BaseResolver.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/motoko/resolvers/base_resolver.rb', line 14

def initialize(name, options)
  options ||= {}

  @name = name
  @human_name = options.delete('human_name') if options.key?('human_name')
  formatter = options.delete('formatter') || 'base_formatter'
  @align = options.delete('align')

  @formatter = Object.const_get("Motoko::Formatters::#{snake_to_camel_case(formatter)}").new(options)

  puts "unused keys for column #{name}: #{options.keys.join(', ')}" if options.keys.any?
end

Instance Attribute Details

#formatterObject (readonly)

Returns the value of attribute formatter.



10
11
12
# File 'lib/motoko/resolvers/base_resolver.rb', line 10

def formatter
  @formatter
end

#human_nameObject



31
32
33
# File 'lib/motoko/resolvers/base_resolver.rb', line 31

def human_name
  @human_name ||= name.tr('_', ' ').gsub('.', ' > ').split.map(&:capitalize).join(' ')
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/motoko/resolvers/base_resolver.rb', line 8

def name
  @name
end

Instance Method Details

#alignObject



27
28
29
# File 'lib/motoko/resolvers/base_resolver.rb', line 27

def align
  @align&.to_sym
end

#resolve_for(_node) ⇒ Object



35
36
37
# File 'lib/motoko/resolvers/base_resolver.rb', line 35

def resolve_for(_node)
  raise 'Not implemented'
end

#value(node) ⇒ Object



39
40
41
# File 'lib/motoko/resolvers/base_resolver.rb', line 39

def value(node)
  formatter.format(resolve_for(node))
end