Sha256: cc75b4f9ce1b751965316376a4dfd8bd4dd8d5f33f7b7211916d4f4a15b75420

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'shellwords'

module Lino
  module Model
    class EnvironmentVariable
      attr_reader :name,
                  :value,
                  :quoting

      def initialize(name, value, opts = {})
        opts = with_defaults(opts)
        @name = name
        @value = value
        @quoting = opts[:quoting]
      end

      def quoted_value
        "#{quoting}#{value.to_s.gsub(quoting.to_s, "\\#{quoting}")}#{quoting}"
      end

      def string
        "#{name}=#{quoted_value}"
      end
      alias to_s string

      def array
        [name, value]
      end
      alias to_a array

      def ==(other)
        self.class == other.class &&
          state == other.state
      end

      alias eql? ==

      def hash
        [self.class, state].hash
      end

      protected

      def state
        [
          @name,
          @value,
          @quoting
        ]
      end

      private

      def with_defaults(opts)
        {
          quoting: opts[:quoting] || '"'
        }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lino-3.2.0.pre.9 lib/lino/model/environment_variable.rb
lino-3.2.0.pre.8 lib/lino/model/environment_variable.rb
lino-3.2.0.pre.7 lib/lino/model/environment_variable.rb
lino-3.2.0.pre.6 lib/lino/model/environment_variable.rb