Class: PopulateEnv::Formatters::EnvShellSection

Inherits:
Object
  • Object
show all
Defined in:
lib/populate_env/formatters/env_shell_section.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, export: false) ⇒ EnvShellSection

Returns a new instance of EnvShellSection.



6
7
8
9
# File 'lib/populate_env/formatters/env_shell_section.rb', line 6

def initialize(attribute, export: false)
  @attribute = attribute
  @export = export
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



4
5
6
# File 'lib/populate_env/formatters/env_shell_section.rb', line 4

def attribute
  @attribute
end

#exportObject (readonly)

Returns the value of attribute export.



4
5
6
# File 'lib/populate_env/formatters/env_shell_section.rb', line 4

def export
  @export
end

Instance Method Details

#prefixObject



11
12
13
# File 'lib/populate_env/formatters/env_shell_section.rb', line 11

def prefix
  export ? "export " : ""
end

#to_sObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/populate_env/formatters/env_shell_section.rb', line 15

def to_s
  output = ''
  
  if attribute.description
    attribute.description.each_line do |line|
      output << "# #{line}\n"
    end
  end
  
  if attribute.optional? && attribute.value.nil?
    output << "# "
  end
  
  output << "#{prefix}#{attribute.name}=#{attribute.value}\n"
end