Class: BankLink::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/bank_link/link.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bank, url) {|form| ... } ⇒ Link

Returns a new instance of Link.

Yields:



5
6
7
8
9
10
# File 'lib/bank_link/link.rb', line 5

def initialize bank, url, &block
  self.bank = bank
  self.url = url
  self.form = Hashie::Mash.new
  yield(form) if block_given?
end

Instance Attribute Details

#bankObject

Returns the value of attribute bank.



3
4
5
# File 'lib/bank_link/link.rb', line 3

def bank
  @bank
end

#formObject

Returns the value of attribute form.



3
4
5
# File 'lib/bank_link/link.rb', line 3

def form
  @form
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/bank_link/link.rb', line 3

def url
  @url
end

Instance Method Details

#apply_encoding(content) ⇒ Object



30
31
32
# File 'lib/bank_link/link.rb', line 30

def apply_encoding content
  content[settings.encoding_key] = settings.encoding if settings.encoding && settings.encoding_key
end

#calculate_keys(content, object) ⇒ Object



24
25
26
27
28
# File 'lib/bank_link/link.rb', line 24

def calculate_keys content, object
  content.each do |key, value|
    content[key] = content[key].call(self, object) if content[key].is_a?(Proc)
  end
end

#calculate_mac(content) ⇒ Object



34
35
36
37
# File 'lib/bank_link/link.rb', line 34

def calculate_mac content
  mac = settings.mac_class.new(self, content)
  content[mac.key] = mac.generate
end

#processed_data(object, overrides = {}) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/bank_link/link.rb', line 16

def processed_data object, overrides={}
  content = Hashie::Mash.new(form.merge(overrides))
  apply_encoding content
  calculate_keys content, object
  calculate_mac content
  content
end

#settings(*args, &block) ⇒ Object



12
13
14
# File 'lib/bank_link/link.rb', line 12

def settings *args, &block
  bank.settings *args, &block
end