Sha256: 444926d85af6f5a5524dac5a1d8f2c3ac7a8d8b46aa0d318466d753dc11e48a8

Contents?: true

Size: 1.28 KB

Versions: 16

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module RubyGPG2
  module StatusLines
    class ImportOK
      REASONS = {
        1 => :new_key,
        2 => :new_user_ids,
        4 => :new_signatures,
        8 => :new_subkeys,
        16 => :private_key
      }.freeze

      def self.parse(line)
        match = line.match(/^\[GNUPG:\] IMPORT_OK (\d+) (.*)$/)
        new(
          raw: line,
          reasons: reasons(match[1]),
          key_fingerprint: match[2]
        )
      end

      attr_reader(
        :raw,
        :reasons,
        :key_fingerprint
      )

      def initialize(opts)
        @raw = opts[:raw]
        @reasons = opts[:reasons]
        @key_fingerprint = opts[:key_fingerprint]
      end

      def type
        :import_ok
      end

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

      protected

      def state
        [
          @raw,
          @reasons,
          @key_fingerprint
        ]
      end

      class << self
        protected

        def reasons(value)
          value = value.to_i
          if value.zero?
            [:no_change]
          else
            REASONS.inject([]) do |r, entry|
              (value & entry[0]).positive? ? (r << entry[1]) : r
            end
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ruby_gpg2-0.13.0.pre.4 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.13.0.pre.3 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.13.0.pre.2 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.13.0.pre.1 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.12.0 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.11.0.pre.7 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.11.0.pre.6 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.11.0.pre.5 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.11.0.pre.4 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.11.0.pre.3 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.11.0.pre.2 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.11.0.pre.1 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.10.0 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.9.0.pre.9 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.9.0.pre.8 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.9.0.pre.7 lib/ruby_gpg2/status_lines/import_ok.rb