⌚ 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

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