Module: Foobara::DomainMapperLookups::ClassMethods
- Defined in:
- foobara-0.0.110/projects/domain_mapper/src/domain_mapper_lookups.rb
Instance Method Summary collapse
- #lookup_matching_domain_mapper(from: nil, to: nil, strict: false, criteria: nil) ⇒ Object
- #lookup_matching_domain_mapper!(from: nil, to: nil, strict: false, criteria: nil) ⇒ Object
- #mappers ⇒ Object
- #new_mapper_registered! ⇒ Object
Instance Method Details
#lookup_matching_domain_mapper(from: nil, to: nil, strict: false, criteria: nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'foobara-0.0.110/projects/domain_mapper/src/domain_mapper_lookups.rb', line 55 def lookup_matching_domain_mapper(from: nil, to: nil, strict: false, criteria: nil) candidates = mappers.select do |mapper| if criteria next unless criteria.call(mapper) end mapper.applicable?(from, to) end if candidates.size > 1 best = [] best_score = 0 candidates.each do |mapper| score = mapper.applicable_score(from, to) if score > best_score best = [mapper] best_score = score elsif score == best_score best << mapper end end if best.size > 1 raise AmbiguousDomainMapperError.new(from, to, candidates) else candidates = best end end value = candidates.first return value if value unless strict if from lookup_matching_domain_mapper(from: nil, to:) elsif to lookup_matching_domain_mapper(from:, to: nil) end end end |
#lookup_matching_domain_mapper!(from: nil, to: nil, strict: false, criteria: nil) ⇒ Object
49 50 51 52 53 |
# File 'foobara-0.0.110/projects/domain_mapper/src/domain_mapper_lookups.rb', line 49 def lookup_matching_domain_mapper!(from: nil, to: nil, strict: false, criteria: nil) result = lookup_matching_domain_mapper(from:, to:, strict:, criteria:) result || raise(NoDomainMapperFoundError.new(from, to)) end |
#mappers ⇒ Object
99 100 101 |
# File 'foobara-0.0.110/projects/domain_mapper/src/domain_mapper_lookups.rb', line 99 def mappers @mappers ||= end |
#new_mapper_registered! ⇒ Object
43 44 45 46 47 |
# File 'foobara-0.0.110/projects/domain_mapper/src/domain_mapper_lookups.rb', line 43 def new_mapper_registered! if defined?(@mappers) && !@mappers.empty? remove_instance_variable("@mappers") end end |