Class: ExampleFile

Inherits:
Object
  • Object
show all
Defined in:
lib/example_file.rb,
lib/example_file/version.rb

Overview

Class for example file

Constant Summary collapse

SUFFIX =
'.example'
HIGHLINE =
HighLine.new
VERSION =
'0.4.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ ExampleFile

Returns a new instance of ExampleFile.



24
25
26
27
28
29
30
31
32
33
# File 'lib/example_file.rb', line 24

def initialize(file_name)
  @file_name = file_name
  @regular_file_name = @file_name.sub SUFFIX, ''

  @basename = Paint[File.basename(@file_name), :green, :bold]
  @regular_basename = Paint[File.basename(@regular_file_name), :red, :bold]

  @choices = DEFAULT_CHOICES.dup
  @question_prefix = nil
end

Instance Attribute Details

#choicesObject (readonly)

Returns the value of attribute choices.



21
22
23
# File 'lib/example_file.rb', line 21

def choices
  @choices
end

#question_prefix=(value) ⇒ Object (writeonly)

Sets the attribute question_prefix

Parameters:

  • value

    the value to set the attribute question_prefix to.



22
23
24
# File 'lib/example_file.rb', line 22

def question_prefix=(value)
  @question_prefix = value
end

Class Method Details

.all(directory) ⇒ Object



15
16
17
18
# File 'lib/example_file.rb', line 15

def all(directory)
  Dir[File.join(directory, '**', "*#{SUFFIX}*")]
    .map { |file_name| new file_name }
end

Instance Method Details

#actualize_regular_fileObject



35
36
37
38
39
40
41
42
43
# File 'lib/example_file.rb', line 35

def actualize_regular_file
  return create_regular_file unless regular_file_exist?

  return unless updated?

  return update_regular_file if diff.chomp.empty?

  ask_question_and_make_actions
end

#initialize_regular_fileObject



45
46
47
48
49
50
51
# File 'lib/example_file.rb', line 45

def initialize_regular_file
  if File.exist? @regular_file_name
    raise "File `#{File.basename(@regular_file_name)}` already exists"
  end

  FileUtils.cp @file_name, @regular_file_name
end