Class: ConvenientService::Examples::Standard::V1::Gemfile::Services::AssertFileNotEmpty

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Config

included

Constructor Details

#initialize(path:) ⇒ AssertFileNotEmpty

Returns a new instance of AssertFileNotEmpty.



19
20
21
# File 'lib/convenient_service/examples/standard/v1/gemfile/services/assert_file_not_empty.rb', line 19

def initialize(path:)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



17
18
19
# File 'lib/convenient_service/examples/standard/v1/gemfile/services/assert_file_not_empty.rb', line 17

def path
  @path
end

Instance Method Details

#resultObject



23
24
25
26
27
28
29
30
# File 'lib/convenient_service/examples/standard/v1/gemfile/services/assert_file_not_empty.rb', line 23

def result
  return failure(data: {path: "Path is `nil`"}) if path.nil?
  return failure(data: {path: "Path is empty"}) if path.empty?

  return error(message: "File with path `#{path}` is empty") if ::File.zero?(path)

  success
end