class BankCredentials::Base

Attributes

credentials[R]

Public Class Methods

attribute(attribute) click to toggle source
# File lib/bank_credentials/base.rb, line 18
def self.attribute(attribute)
  @attributes = [] if @attributes.nil?
  @attributes << attribute
  def_delegator :@credentials, attribute
  def_delegator :@credentials, "#{attribute}=".to_sym
end
attributes() click to toggle source
# File lib/bank_credentials/base.rb, line 13
def self.attributes
  @attributes = [] if @attributes.nil?
  @attributes
end
new(credential_hash, options = {}) click to toggle source
# File lib/bank_credentials/base.rb, line 25
def initialize(credential_hash, options = {})
  credential_hash[:type] = credential_hash[:type] || self.class.type || nil
  @credentials = OpenStruct.new(credential_hash)
  validate! if options[:validate]
end
type() click to toggle source
# File lib/bank_credentials/base.rb, line 9
def self.type
  name.nil? ? 'base' : name.split('::').last.downcase
end

Public Instance Methods

attributes() click to toggle source
# File lib/bank_credentials/base.rb, line 39
def attributes
  self.class.attributes
end
encode() click to toggle source
# File lib/bank_credentials/base.rb, line 35
def encode
  Base64.urlsafe_encode64(to_json)
end
to_json() click to toggle source
# File lib/bank_credentials/base.rb, line 31
def to_json
  to_h.to_json
end
valid?() click to toggle source
# File lib/bank_credentials/base.rb, line 43
def valid?
  attributes.each do |attribute|
    return false if @credentials[attribute].nil? || @credentials[attribute].empty?
  end
end
validate!() click to toggle source
# File lib/bank_credentials/base.rb, line 49
def validate!
  raise self.class::Errors::Invalid unless valid?
end