···11require_relative 'modules/configurable'
22require_relative 'modules/interactions'
33require_relative 'modules/feeds'
44+require_relative 'errors'
4556module BlueFactory
67 extend Configurable
···1011 #
1112 # The server's `did:web:` service DID built from the configured hostname.
1213 # @return [String]
1414+ # @raise [ConfigurationError] if the hostname is not set
1315 #
1416 def self.service_did
1717+ if hostname.nil?
1818+ raise ConfigurationError, "The `hostname` property is not set. Set it with: BlueFactory.set(:hostname, 'example.com')"
1919+ end
2020+1521 'did:web:' + hostname
1622 end
1723
+7
lib/blue_factory/errors.rb
···2626 end
27272828 #
2929+ # Raised when some required configuration is missing.
3030+ #
3131+3232+ class ConfigurationError < StandardError
3333+ end
3434+3535+ #
2936 # Raised when configuring the available feeds if a provided feed key is invalid.
3037 #
3138
+35
lib/blue_factory/server.rb
···2121 #
22222323 class Server < Sinatra::Base
2424+2525+ # @private
2626+ @@config_checked = false
2727+2828+ # Run the Sinatra app as a self-hosted server.
2929+ # See {https://www.rubydoc.info/gems/sinatra/Sinatra/Base#run!-class_method Sinatra::Base.run!}.
3030+ # @raise [ConfigurationError] if the {BlueFactory.hostname} or {BlueFactory.publisher_did} is not set
3131+3232+ def self.run!(options = {}, &block)
3333+ verify_config
3434+ super
3535+ end
3636+3737+ before do
3838+ Server.send(:verify_config) unless @@config_checked
3939+ end
4040+2441 configure do
2542 disable :static
2643 enable :quiet
···140157 json_error('MethodNotImplemented', 'Method Not Implemented', status: 501)
141158 end
142159 end
160160+161161+162162+ private
163163+164164+ def self.verify_config
165165+ if BlueFactory.hostname.nil?
166166+ raise ConfigurationError, "The `hostname` property is not set. Set it with: BlueFactory.set(:hostname, 'example.com')"
167167+ end
168168+169169+ if BlueFactory.publisher_did.nil?
170170+ raise ConfigurationError,
171171+ "The `publisher_did` property is not set. Set it with: BlueFactory.set(:publisher_did, 'did:plc:qweqweqwe')"
172172+ end
173173+174174+ @@config_checked = true
175175+ end
176176+177177+ private_class_method :verify_config
143178 end
144179end