Mirror of Github Repo. https://github.com/flockingbird/roost
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.

environment.rb 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # frozen_string_literal: true
  2. require 'mail'
  3. require 'uuidtools'
  4. require 'event_sourcery'
  5. require 'event_sourcery/postgres'
  6. require "#{__dir__}/../app/errors"
  7. Dir.glob("#{__dir__}/../lib/*.rb").sort.each { |f| require f }
  8. Dir.glob("#{__dir__}/../app/events/*.rb").sort.each { |f| require f }
  9. Dir.glob("#{__dir__}/../app/reactors/*.rb").sort.each { |f| require f }
  10. Dir.glob("#{__dir__}/../app/projections/**/projector.rb").sort.each do |f|
  11. require f
  12. end
  13. ##
  14. # The main app, integrated under Roost
  15. class Roost
  16. ##
  17. # Holds the configuration for Roost. Mainly event-sourcery config.
  18. class Config
  19. attr_accessor :database_url, :secret_base, :web_url
  20. end
  21. def self.config
  22. @config ||= Config.new
  23. end
  24. def self.configure
  25. yield config
  26. end
  27. def self.production?
  28. environment == 'production'
  29. end
  30. def self.development?
  31. environment == 'development'
  32. end
  33. def self.test?
  34. environment == 'test'
  35. end
  36. def self.environment
  37. ENV.fetch('APP_ENV', 'development')
  38. end
  39. def self.root
  40. Pathname.new(File.expand_path("#{__dir__}/../"))
  41. end
  42. def self.event_store
  43. EventSourcery::Postgres.config.event_store
  44. end
  45. def self.event_source
  46. EventSourcery::Postgres.config.event_store
  47. end
  48. def self.tracker
  49. EventSourcery::Postgres.config.event_tracker
  50. end
  51. def self.event_sink
  52. EventSourcery::Postgres.config.event_sink
  53. end
  54. def self.projections_database
  55. EventSourcery::Postgres.config.projections_database
  56. end
  57. def self.all_processors
  58. [
  59. Reactors::InvitationMailer,
  60. Reactors::ConfirmationMailer,
  61. Reactors::MemberGenerator,
  62. Reactors::Follower,
  63. Projections::Contacts::Projector,
  64. Projections::Invitations::Projector,
  65. Projections::Members::Projector,
  66. Projections::Updates::Projector
  67. ]
  68. end
  69. def self.repository
  70. @repository ||= EventSourcery::Repository.new(
  71. event_source: event_source,
  72. event_sink: event_sink
  73. )
  74. end
  75. def self.base_path
  76. Pathname.new(File.join(__dir__, '..'))
  77. end
  78. end
  79. unless Roost.production?
  80. require 'dotenv'
  81. Dotenv.load(Roost.base_path.join(".env.#{ENV['APP_ENV']}"),
  82. Roost.base_path.join('.env'))
  83. end
  84. Roost.configure do |config|
  85. config.web_url = 'https://example.com'
  86. config.secret_base = ENV['SECRET_BASE']
  87. config.database_url = ENV['DATABASE_URL']
  88. Mail.defaults do
  89. delivery_method(
  90. ENV['MAIL_METHOD'].to_sym,
  91. address: ENV['SMTP_ADDRESS'],
  92. port: ENV['SMTP_PORT'],
  93. user_name: ENV['SMTP_USER_NAME'],
  94. password: ENV['SMTP_PASSWORD'],
  95. enable_starttls: ENV['SMTP_STARTTLS'],
  96. domain: ENV['SMTP_DOMAIN']
  97. )
  98. end
  99. end
  100. require Roost.root.join('lib/handle')