|
| 1 | +require_relative "command_base" |
| 2 | +require_relative "execution_result" |
| 3 | +require_relative "service_base" |
| 4 | +require_relative "DataProxies/DatabaseProxies/customer_database_proxy" |
| 5 | +require_relative "DataProxies/RestfulServiceProxies/customer_restful_proxy" |
| 6 | +require_relative "Rules/field_length_rule" |
| 7 | +require_relative "Rules/field_required_rule" |
| 8 | + |
| 9 | +class CustomerService < ServiceBase |
| 10 | + def initialize(data_proxy) |
| 11 | + super(data_proxy) |
| 12 | + end |
| 13 | + def rules_for_insert(entity) |
| 14 | + rules = [] |
| 15 | + rules << FieldRequiredRule.new(entity, :name) |
| 16 | + .if_valid_then_execute(lambda { |rule| puts "WOOT!" }) |
| 17 | + .if_valid_then_validate(FieldLengthRule.new(entity, :name, 10) |
| 18 | + .if_invalid_then_execute(lambda { |rule| puts "ARGH!!" })) |
| 19 | + rules |
| 20 | + end |
| 21 | +end |
| 22 | + |
| 23 | +#customer_data_proxy = CustomerRestfulProxy.new |
| 24 | +customer_data_proxy = CustomerDatabaseProxy.new |
| 25 | + |
| 26 | +service = CustomerService.new(customer_data_proxy) |
| 27 | + |
| 28 | +commands = [] |
| 29 | +commands << service.insert_command({:id => 1, :name => ""}) |
| 30 | +commands << service.insert_command({:id => 2, :name => "Foo Bar"}) |
| 31 | +commands << service.insert_command({:id => 3, :name => ""}) |
| 32 | +commands << service.insert_command({:id => 4, :name => "Mikasaessucasa"}) |
| 33 | +commands << service.insert_command({:id => 5, :name => "John"}) |
| 34 | +commands << service.insert_command({:id => 6, :name => ""}) |
| 35 | +commands << service.insert_command({:id => 7, :name => ""}) |
| 36 | +commands << service.insert_command({:id => 8, :name => "meh"}) |
| 37 | +commands << service.insert_command({:id => 9, :name => ""}) |
| 38 | +commands << service.insert_command({:id => 10, :name => "Aargssssssssss"}) |
| 39 | +commands << service.insert_command({:id => 11, :name => ""}) |
| 40 | + |
| 41 | +results = [] |
| 42 | +threads = commands.map { |command| Thread.new(command) { |command| results << command.execute } } |
| 43 | +threads.each { |t| t.join } |
| 44 | + |
| 45 | +results.each { |result| puts result.inspect } |
0 commit comments