Class: Wordmove::Doctor::Movefile

Inherits:
Object
  • Object
show all
Defined in:
lib/wordmove/doctor/movefile.rb

Constant Summary collapse

MANDATORY_SECTIONS =
%i[global local].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, dir = '.') ⇒ Movefile

Returns a new instance of Movefile.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/wordmove/doctor/movefile.rb', line 7

def initialize(name = nil, dir = '.')
  @movefile = Wordmove::Movefile.new(name, dir)

  begin
    @contents = movefile.fetch
    @root_keys = contents.keys
  rescue Psych::SyntaxError
    movefile.logger.error "Your movefile is not parsable due to a syntax error"\
                          "so we can't continue to validate it."
    movefile.logger.debug "You could try to use https://yamlvalidator.com/ to"\
                          "get a clue about the problem."
  end
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



5
6
7
# File 'lib/wordmove/doctor/movefile.rb', line 5

def contents
  @contents
end

#movefileObject (readonly)

Returns the value of attribute movefile.



5
6
7
# File 'lib/wordmove/doctor/movefile.rb', line 5

def movefile
  @movefile
end

#root_keysObject (readonly)

Returns the value of attribute root_keys.



5
6
7
# File 'lib/wordmove/doctor/movefile.rb', line 5

def root_keys
  @root_keys
end

Instance Method Details

#validate!Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/wordmove/doctor/movefile.rb', line 21

def validate!
  return false unless root_keys

  MANDATORY_SECTIONS.each do |key|
    movefile.logger.task "Validating movefile section: #{key}"
    validate_mandatory_section(key)
  end

  root_keys.each do |remote|
    movefile.logger.task "Validating movefile section: #{remote}"
    validate_remote_section(remote)
  end
end