Permalink
Browse files

config.ru for bundled gems

  • Loading branch information...
1 parent c7f53bd commit 51df347bc0f4fbb819b3e643a8ac6051a764733b svs committed Nov 16, 2009
View
@@ -27,4 +27,5 @@ config/database.yml
*pdf
public/logs
uploads
-
+nbproject
+config.ru.bak
@@ -40,6 +40,7 @@ def update(id, loan_product)
@loan_product = LoanProduct.get(id)
raise NotFound unless @loan_product
loan_product[:payment_validation_methods] = params[:payment_validations].keys.join(",")
+ loan_product[:loan_validation_methods] = params[:loan_validations].keys.join(",")
if @loan_product.update_attributes(loan_product)
redirect resource(@loan_product)
else
View
@@ -666,14 +666,6 @@ def amount_greater_than_zero?
return true if not amount.blank? and amount > 0
[false, "Loan amount should be greater than zero"]
end
- def installments_are_integers?
- return [false, "Number of installments not defined"] if number_of_installments.nil? or number_of_installments.blank?
- (1..number_of_installments).each do |i|
- p = scheduled_principal_for_installment(i)
- return [false, "Amount must yield integer installments"] if p.to_i != p
- end
- return true
- end
def interest_rate_greater_than_zero?
return true if interest_rate and interest_rate.to_f > 0
[false, "Interest rate should be greater than zero"]
@@ -40,11 +40,11 @@ def self.from_csv(row, headers)
end
def payment_validations
- payment_validation_methods.split(",").each.map{|m| m.to_sym}
+ (payment_validation_methods or "").split(",").each.map{|m| m.to_sym}
end
def loan_validations
- loan_validation_methods.split(",").each.map{|m| m.to_sym}
+ (loan_validation_methods or "").split(",").each.map{|m| m.to_sym}
end
def self.valid(date=Date.today)
View
@@ -1,16 +1,17 @@
module Misfit
- # ALL payment validations go in here so that they are available to the loan product
+
module PaymentValidators
+ # ALL payment validations go in here so that they are available to the loan product
def amount_must_be_paid_in_full_or_not_at_all
case type
when :principal
- if amount < loan.principal_due_on(received_on) and amount != 0
+ if amount < loan.scheduled_principal_due_on(received_on) and amount != 0
return [false, "amount must be paid in full or not at all"]
else
return true
end
when :interest
- if amount < loan.interest_due_on(received_on) and amount != 0
+ if amount < loan.scheduled_interest_due_on(received_on) and amount != 0
return [false, "amount must be paid in full or not at all"]
else
return true
@@ -19,12 +20,21 @@ def amount_must_be_paid_in_full_or_not_at_all
end
def other_validation
- return true
+ return [false, "other validation failed"]
end
- end
+ end #PaymentValidators
module LoanValidators
- end
+ def installments_are_integers?
+ return [false, "Number of installments not defined"] if number_of_installments.nil? or number_of_installments.blank?
+ (1..number_of_installments).each do |i|
+ p = scheduled_principal_for_installment(i)
+ return [false, "Amount must yield integer installments"] if p.to_i != p
+ end
+ return true
+ end
+ end #LoanValidators
+
end
@@ -30,5 +30,9 @@
- Misfit::PaymentValidators.instance_methods.each do |v|
= check_box :name => "payment_validations[#{v}]", :checked => @loan_product.payment_validations.include?(v.to_sym)
= v.humanize
+%h2 Payment Validations
+- Misfit::LoanValidators.instance_methods.each do |v|
+ = check_box :name => "loan_validations[#{v}]", :checked => @loan_product.loan_validations.include?(v.to_sym)
+ = v.humanize
%br
@@ -1,7 +1,7 @@
%h1
Loan products
%table
- - [:name, :loan_type, :min_amount, :max_amount, :min_interest_rate, :max_interest_rate, :min_number_of_installments, :max_number_of_installments, :installment_frequency, :valid_from, :valid_upto, :payment_validation_methods].each do |attr|
+ - [:name, :loan_type, :min_amount, :max_amount, :min_interest_rate, :max_interest_rate, :min_number_of_installments, :max_number_of_installments, :installment_frequency, :valid_from, :valid_upto, :payment_validation_methods, :loan_validation_methods].each do |attr|
%tr
%td
= attr.humanize
View
@@ -1,14 +1,23 @@
# config.ru
require 'rubygems'
-if File.join(File.dirname(__FILE__), "bin", "common.rb")
- require File.join(File.dirname(__FILE__), "bin", "common")
-end
+
+# Uncomment if your app uses bundled gems.
+# gems_dir = File.expand_path(File.join(File.dirname(__FILE__), 'gems'))
+# Gem.clear_paths
+# $BUNDLE = true
+# Gem.path.unshift(gems_dir)
+
require 'merb-core'
-
-Merb::Config.setup(:merb_root => ".",
+
+Merb::Config.setup(:merb_root => File.expand_path(File.dirname(__FILE__)),
:environment => ENV['RACK_ENV'])
-Merb.environment = Merb::Config[:environment]
+Merb.environment = "production" #Merb::Config[:environment]
Merb.root = Merb::Config[:merb_root]
Merb::BootLoader.run
-
-run Merb::Rack::Application.new
+
+# Uncomment if your app is mounted at a suburi.
+# if prefix = ::Merb::Config[:path_prefix]
+# use Merb::Rack::PathPrefix, prefix
+# end
+
+run Merb::Rack::Application.new
View
@@ -65,11 +65,11 @@
# ruby is too beautiful. 3 lines of code and all payments can get their appropriate validations which are decided by the
# loan product.
Misfit::PaymentValidators.instance_methods.map{|m| m.to_sym}.each do |s|
- clause = eval("Proc.new{|t| t.loan and (t.loan.loan_product.payment_validations.index(:#{s}) != nil)}")
+ clause = Proc.new{|t| t.loan and (t.loan.loan_product.payment_validations.include?(s))}
Payment.add_validator_to_context({:context => :default, :if => clause}, [s], DataMapper::Validate::MethodValidator)
end
Misfit::LoanValidators.instance_methods.map{|m| m.to_sym}.each do |s|
- clause = eval("Proc.new{|t| t.loan and (t.loan.loan_product.loan_validations.index(:#{s}) != nil)}")
+ clause = Proc.new{|t| t.loan and (t.loan.loan_product.loan_validations.include?(s))}
Loan.add_validator_to_context({:context => :default, :if => clause}, [s], DataMapper::Validate::MethodValidator)
end

0 comments on commit 51df347

Please sign in to comment.