Class: Fitting::Prefix

Inherits:
Object
  • Object
show all
Defined in:
lib/fitting/prefix.rb

Defined Under Namespace

Classes: NotFound, Skip

Constant Summary collapse

KEYS =
{
  'openapi2' => :openapi2_json_path,
  'openapi3' => :openapi3_yaml_path,
  'drafter' => :drafter_yaml_path,
  'crafter' => :crafter_yaml_path,
  'tomogram' => :tomogram_json_path
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, schema_paths, type, skip = false) ⇒ Prefix

Returns a new instance of Prefix.

Raises:



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fitting/prefix.rb', line 15

def initialize(name, schema_paths, type, skip = false)
  @prefix = name
  @cover = false

  @actions = Fitting::Report::Actions.new([])
  raise Skip if skip

  schema_paths.each do |path|
    tomogram = Tomograph::Tomogram.new(prefix: name, KEYS[type] => path)

    @actions.push(Fitting::Report::Actions.new(tomogram))
  end
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



13
14
15
# File 'lib/fitting/prefix.rb', line 13

def actions
  @actions
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/fitting/prefix.rb', line 13

def name
  @name
end

Class Method Details

.find(host:, log:) ⇒ Object

Raises:



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fitting/prefix.rb', line 40

def self.find(host:, log:)
  yaml = YAML.safe_load(File.read('.fitting.yml'))

  prefixes = yaml['hosts'].find{|h| h.first.first == host.to_s}.first.last['prefixes']
  raise NotFound.new("host: #{log.host}, path: #{log.path}", log) unless prefixes

  prefix = prefixes.find do |prefix|
    prefix['name'].nil? || log.path[0..prefix['name'].size - 1] == prefix['name']
  end
  raise NotFound.new("host: #{log.host}, path: #{log.path}", log) unless prefix

  new(prefix['name'], prefix['schema_paths'], prefix['type'], prefix['skip'])
end

Instance Method Details

#cover!Object



54
55
56
# File 'lib/fitting/prefix.rb', line 54

def cover!
  @cover = true
end

#cover?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/fitting/prefix.rb', line 58

def cover?
  @cover
end