⌚ OpenOpeningstijden main server application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hours.rb 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # frozen_string_literal: true
  2. require 'event_sourcery'
  3. require 'event_sourcery/postgres'
  4. require 'sequel-postgis-georuby'
  5. require 'securerandom'
  6. require_relative '../app/events/node_added.rb'
  7. require_relative '../app/commands/node/add.rb'
  8. require_relative '../app/aggregates/node.rb'
  9. require_relative '../app/projections/nodes.rb'
  10. require_relative '../app/projections/query.rb'
  11. # Monkey patch
  12. class Hash
  13. def slice(*keys)
  14. keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
  15. keys.each_with_object(self.class.new) do |k, hash|
  16. hash[k] = self[k] if key?(k)
  17. end
  18. end
  19. end
  20. ## Core namespace for the app
  21. module Hours
  22. ## Holds the configuration, singleton with a class variable.
  23. class Config
  24. attr_accessor :database_url
  25. # Helper to connect to the main PG database in order to create extensions,
  26. # drop, alter or create databases.
  27. def postgres_database_url
  28. URI.parse(database_url).tap { |url| url.path = '/postgres' }.to_s
  29. end
  30. end
  31. def self.config
  32. @config ||= Config.new
  33. end
  34. def self.configure
  35. yield config
  36. end
  37. def self.environment
  38. ENV.fetch('RACK_ENV', ENV['APP_ENV'] || 'development')
  39. end
  40. def self.event_store
  41. EventSourcery::Postgres.config.event_store
  42. end
  43. def self.event_source
  44. EventSourcery::Postgres.config.event_store
  45. end
  46. def self.tracker
  47. EventSourcery::Postgres.config.event_tracker
  48. end
  49. def self.event_sink
  50. EventSourcery::Postgres.config.event_sink
  51. end
  52. def self.projections_database
  53. EventSourcery::Postgres.config.projections_database
  54. end
  55. def self.repository
  56. @repository ||= EventSourcery::Repository.new(
  57. event_source: event_source,
  58. event_sink: event_sink
  59. )
  60. end
  61. end
  62. require_relative '../config/environment.rb'