Sha256: 463ebe608988dd84abdf5cbdb76f91b46b043ce323a763584f75fc1c27ef106a

Contents?: true

Size: 1.04 KB

Versions: 8

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.to_s, value.to_s]
      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

8 entries across 8 versions & 1 rubygems

Version Path
lino-4.2.0.pre.2 lib/lino/model/environment_variable.rb
lino-4.2.0.pre.1 lib/lino/model/environment_variable.rb
lino-4.1.0 lib/lino/model/environment_variable.rb
lino-4.1.0.pre.2 lib/lino/model/environment_variable.rb
lino-4.1.0.pre.1 lib/lino/model/environment_variable.rb
lino-4.0.0 lib/lino/model/environment_variable.rb
lino-4.0.0.pre.2 lib/lino/model/environment_variable.rb
lino-3.2.0.pre.10 lib/lino/model/environment_variable.rb