Class: CrossPlane::Builder
- Inherits:
-
Object
- Object
- CrossPlane::Builder
- Defined in:
- lib/crossplane/builder.rb
Constant Summary collapse
- DELIMITERS =
['{', '}', ';']
- EXTERNAL_BUILDERS =
{}
- NEWLINE =
"\n"
- TAB =
"\t"
Instance Attribute Summary collapse
-
#header ⇒ Object
Returns the value of attribute header.
-
#indent ⇒ Object
Returns the value of attribute indent.
-
#padding ⇒ Object
Returns the value of attribute padding.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#state ⇒ Object
Returns the value of attribute state.
-
#tabs ⇒ Object
Returns the value of attribute tabs.
Instance Method Summary collapse
- #build(*args) ⇒ Object
-
#initialize(*args) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(*args) ⇒ Builder
Returns a new instance of Builder.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/crossplane/builder.rb', line 22 def initialize(*args) args = args[0] || {} required = ['payload'] conflicts = [] requires = {} valid = { 'params' => [ 'header', 'indent', 'payload', 'tabs', ] } content = CrossPlane.utils.validate_constructor(client: self, args: args, required: required, conflicts: conflicts, requires: requires, valid: valid) self.header = (content[:header] && content[:header] == true) ? true : false self.indent = content[:indent] ? content[:indent] : 4 self.payload = content[:payload] ? content[:payload] : nil self.tabs = (content[:tabs] && content[:tabs] == true) ? true : false end |
Instance Attribute Details
#header ⇒ Object
Returns the value of attribute header.
15 16 17 |
# File 'lib/crossplane/builder.rb', line 15 def header @header end |
#indent ⇒ Object
Returns the value of attribute indent.
16 17 18 |
# File 'lib/crossplane/builder.rb', line 16 def indent @indent end |
#padding ⇒ Object
Returns the value of attribute padding.
17 18 19 |
# File 'lib/crossplane/builder.rb', line 17 def padding @padding end |
#payload ⇒ Object
Returns the value of attribute payload.
18 19 20 |
# File 'lib/crossplane/builder.rb', line 18 def payload @payload end |
#state ⇒ Object
Returns the value of attribute state.
19 20 21 |
# File 'lib/crossplane/builder.rb', line 19 def state @state end |
#tabs ⇒ Object
Returns the value of attribute tabs.
20 21 22 |
# File 'lib/crossplane/builder.rb', line 20 def tabs @tabs end |
Instance Method Details
#build(*args) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/crossplane/builder.rb', line 44 def build(*args) self.padding = self.tabs ? TAB : ' ' * self.indent self.state = { 'prev_obj' => nil, 'depth' => -1, } if self.header lines = [ "# This config was built from JSON using NGINX crossplane.\n", "# If you encounter any bugs please report them here:\n", "# https://github.com/gdanko/crossplane/issues\n", "\n" ] else lines = [] end lines += _build_lines(payload) lines.join('') end |