Class: Pacioli::CompanyValidator
- Inherits:
-
Object
- Object
- Pacioli::CompanyValidator
- Defined in:
- lib/pacioli/validations/company_validator.rb
Instance Attribute Summary collapse
-
#company ⇒ Object
Returns the value of attribute company.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#company ⇒ Object
Returns the value of attribute company.
3 4 5 |
# File 'lib/pacioli/validations/company_validator.rb', line 3 def company @company end |
Class Method Details
.for(company) ⇒ Object
5 6 7 8 9 |
# File 'lib/pacioli/validations/company_validator.rb', line 5 def self.for(company) validator = new validator.company = company validator end |
Instance Method Details
#execute ⇒ Object
11 12 13 |
# File 'lib/pacioli/validations/company_validator.rb', line 11 def execute validate_accounts end |
#validate_accounts ⇒ Object
15 16 17 18 |
# File 'lib/pacioli/validations/company_validator.rb', line 15 def validate_accounts accounts = self.company.accounts.map(&:name) raise Pacioli::CompanyAccountException, "The company has multiple accounts with the same name: '#{accounts.detect{ |e| accounts.count(e) > 1 }}' already exists" unless accounts.detect{ |e| accounts.count(e) > 1 }.nil? end |