Class: ConvenientService::Examples::Standard::Gemfile::Services::AssertValidRubySyntax

Inherits:
Object
  • Object
show all
Includes:
Service::Configs::Standard
Defined in:
lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Service::Configs::Standard

service?, service_class?

Methods included from Config

included

Constructor Details

#initialize(content:) ⇒ AssertValidRubySyntax

Returns a new instance of AssertValidRubySyntax.



18
19
20
# File 'lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb', line 18

def initialize(content:)
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



16
17
18
# File 'lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb', line 16

def content
  @content
end

Instance Method Details

#resultObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb', line 22

def result
  ##
  # NOTE: `> /dev/null 2>&1` is used to hide output.
  # https://unix.stackexchange.com/a/119650/394253
  #
  check_ruby_syntax_result = Services::RunShellCommand.result(command: "ruby -c #{file.path} > /dev/null 2>&1")

  return error("`#{content}` contains invalid Ruby syntax") unless check_ruby_syntax_result.success?

  success
end