Sha256: 7820c8c88f5301e5eaf8c2e476d1754e843d2b380f96807ef3aa74ddff0ea39e

Contents?: true

Size: 1.23 KB

Versions: 17

Compression:

Stored size: 1.23 KB

Contents

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

      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

      private

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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ruby_gpg2-0.9.0.pre.6 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.9.0.pre.5 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.9.0.pre.4 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.9.0.pre.3 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.9.0.pre.2 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.9.0.pre.1 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.8.0 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.7.0.pre.1 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.6.0 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.5.0.pre.1 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.4.0 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.3.0.pre.2 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.3.0.pre.1 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.2.0 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.1.0.pre.27 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.1.0.pre.26 lib/ruby_gpg2/status_lines/import_ok.rb
ruby_gpg2-0.1.0.pre.25 lib/ruby_gpg2/status_lines/import_ok.rb