Class: BankCredentials::Base
- Inherits:
-
Object
- Object
- BankCredentials::Base
- Extended by:
- Forwardable
- Defined in:
- lib/bank_credentials/base.rb
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
- #encode ⇒ Object
-
#initialize(credential_hash, options = {}) ⇒ Base
constructor
A new instance of Base.
- #to_json ⇒ Object
- #valid? ⇒ Boolean
- #validate! ⇒ Object
Constructor Details
#initialize(credential_hash, options = {}) ⇒ Base
25 26 27 28 29 |
# File 'lib/bank_credentials/base.rb', line 25 def initialize(credential_hash, = {}) credential_hash[:type] = credential_hash[:type] || self.class.type || nil @credentials = OpenStruct.new(credential_hash) validate! if [:validate] end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
6 7 8 |
# File 'lib/bank_credentials/base.rb', line 6 def credentials @credentials end |
Class Method Details
.attribute(attribute) ⇒ Object
18 19 20 21 22 23 |
# 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 ⇒ Object
13 14 15 16 |
# File 'lib/bank_credentials/base.rb', line 13 def self.attributes @attributes = [] if @attributes.nil? @attributes end |
.type ⇒ Object
9 10 11 |
# File 'lib/bank_credentials/base.rb', line 9 def self.type name.nil? ? 'base' : name.split('::').last.downcase end |
Instance Method Details
#attributes ⇒ Object
39 40 41 |
# File 'lib/bank_credentials/base.rb', line 39 def attributes self.class.attributes end |
#encode ⇒ Object
35 36 37 |
# File 'lib/bank_credentials/base.rb', line 35 def encode Base64.urlsafe_encode64(to_json) end |
#to_json ⇒ Object
31 32 33 |
# File 'lib/bank_credentials/base.rb', line 31 def to_json to_h.to_json end |
#valid? ⇒ Boolean
43 44 45 46 47 |
# 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! ⇒ Object
49 50 51 |
# File 'lib/bank_credentials/base.rb', line 49 def validate! raise self.class::Errors::Invalid unless valid? end |