⌚ 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.8KB

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