Class: SaveTheMonth::PaymentDsl

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/payment_dsl.rb', line 10

def method_missing(meth, *args, &blk)      
  payment_name = meth
  
  if block_given?
    expected_balance.add_payment(payment_name, &blk)
  else
    amount, options = args[0], args[1]
    amount_date = Date.parse(options[:at])
    expected_balance.add_timed_payment(payment_name, amount, amount_date)
  end
end

Instance Attribute Details

#expected_balanceObject

Returns the value of attribute expected_balance.



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

def expected_balance
  @expected_balance
end

Instance Method Details

#evaluate_recipe(expected_balance, &recipe) ⇒ Object



5
6
7
8
# File 'lib/payment_dsl.rb', line 5

def evaluate_recipe(expected_balance, &recipe)
  self.expected_balance = expected_balance
  instance_eval(&recipe)
end