Class: Avmtrf1::Openvpn::Config::Builder
- Inherits:
-
Object
- Object
- Avmtrf1::Openvpn::Config::Builder
- Defined in:
- lib/avmtrf1/openvpn/config/builder.rb
Instance Method Summary collapse
- #data ⇒ Object
- #on_data_file ⇒ Object
- #simple ⇒ Object
- #simple_add_or_update(name, args) ⇒ Object
- #simple_find(name) ⇒ Object
- #tag_to_data(tag) ⇒ Object
- #tags ⇒ Object
Instance Method Details
#data ⇒ Object
17 18 19 |
# File 'lib/avmtrf1/openvpn/config/builder.rb', line 17 def data [simple, ].reject(&:blank?).join("\n") # rubocop:disable Rails/CompactBlank end |
#on_data_file ⇒ Object
21 22 23 24 25 26 |
# File 'lib/avmtrf1/openvpn/config/builder.rb', line 21 def on_data_file ::EacRubyUtils::Fs::Temp.on_file do |file| file.write(data) yield(file) end end |
#simple ⇒ Object
28 29 30 31 32 |
# File 'lib/avmtrf1/openvpn/config/builder.rb', line 28 def simple source_data.fetch(:simple) .map { |s| ::Shellwords.join([s.fetch(:attribute)] + s.fetch(:args)) } .map { |s| "#{s}\n" }.join end |
#simple_add_or_update(name, args) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/avmtrf1/openvpn/config/builder.rb', line 34 def simple_add_or_update(name, args) new_data = { attribute: name, args: args } s = simple_find(name) if s s.merge!(new_data) else source_data.fetch(:simple) << new_data end end |
#simple_find(name) ⇒ Object
53 54 55 |
# File 'lib/avmtrf1/openvpn/config/builder.rb', line 53 def simple_find(name) source_data.fetch(:simple).find { |s| s.fetch(:attribute) == name } end |
#tag_to_data(tag) ⇒ Object
48 49 50 51 |
# File 'lib/avmtrf1/openvpn/config/builder.rb', line 48 def tag_to_data(tag) ["<#{tag.fetch(:name)}>", tag.fetch(:content), "</#{tag.fetch(:name)}>"] .map { |v| "#{v}\n" }.join end |
#tags ⇒ Object
44 45 46 |
# File 'lib/avmtrf1/openvpn/config/builder.rb', line 44 def source_data.fetch(:tags).map { |t| tag_to_data(t) } end |