Sha256: 86cc820df1d08ec12f89fff98d5cd213439fafb2636994fe5f1e304ddce39116

Contents?: true

Size: 657 Bytes

Versions: 7

Compression:

Stored size: 657 Bytes

Contents

# frozen_string_literal: true

require 'yaml'

module Toggl
  module Jobcan
    # Jobcan credentials manager
    class Credentials
      attr_accessor :email
      attr_accessor :password

      ATTRS = %i[email password].freeze

      def initialize(args)
        attr_set(args) if args.key?(:email)
        c = self.class.load_config(args[:path])
        attr_set(c)
      end

      class << self
        def load_config(path)
          YAML.safe_load(File.open(path).read).transform_keys(&:to_sym)
        end
      end

      private

      def attr_set(hash)
        ATTRS.each { |k| send((k.to_s + '=').to_sym, hash[k]) }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
toggl-jobcan-0.5.0 lib/toggl/jobcan/credentials.rb
toggl-jobcan-0.4.3 lib/toggl/jobcan/credentials.rb
toggl-jobcan-0.4.2 lib/toggl/jobcan/credentials.rb
toggl-jobcan-0.4.1 lib/toggl/jobcan/credentials.rb
toggl-jobcan-0.4.0 lib/toggl/jobcan/credentials.rb
toggl-jobcan-0.3.1 lib/toggl/jobcan/credentials.rb
toggl-jobcan-0.3.0 lib/toggl/jobcan/credentials.rb