Class: ConfCtl::NixFormat
- Inherits:
-
Object
- Object
- ConfCtl::NixFormat
- Defined in:
- lib/confctl/nix_format.rb
Overview
Format Ruby values in Nix
Class Method Summary collapse
Instance Method Summary collapse
- #indent ⇒ Object
-
#initialize(sort: true) ⇒ NixFormat
constructor
A new instance of NixFormat.
- #pad(str, indent: true) ⇒ Object
- #to_nix(value) ⇒ String
Constructor Details
#initialize(sort: true) ⇒ NixFormat
Returns a new instance of NixFormat.
14 15 16 17 18 |
# File 'lib/confctl/nix_format.rb', line 14 def initialize(sort: true) @sort = sort @output = '' @level = 0 end |
Class Method Details
.to_nix(value, sort: true) ⇒ String
9 10 11 |
# File 'lib/confctl/nix_format.rb', line 9 def self.to_nix(value, sort: true) new(sort:).to_nix(value) end |
Instance Method Details
#indent ⇒ Object
34 35 36 37 38 |
# File 'lib/confctl/nix_format.rb', line 34 def indent @level += 2 yield @level -= 2 end |
#pad(str, indent: true) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/confctl/nix_format.rb', line 26 def pad(str, indent: true) if indent "#{' ' * @level}#{str}" else str end end |
#to_nix(value) ⇒ String
22 23 24 |
# File 'lib/confctl/nix_format.rb', line 22 def to_nix(value) format_value(value).strip end |