Module: Toast
- Defined in:
- lib/toast.rb,
lib/toast/engine.rb,
lib/toast/version.rb,
lib/toast/config_dsl.rb
Defined Under Namespace
Modules: ConfigDSL, Errors, RequestHelpers Classes: CanonicalRequest, CollectionRequest, ConfigError, Engine, HttpRange, PluralAssocRequest, RackApp, SingleRequest, SingularAssocRequest
Constant Summary collapse
- Sym =
The BREAD
"\xF0\x9F\x8D\x9E"
- VERSION =
'1.0.1'
- @@expositions =
config data of all expose blocks
[]
- @@current_expose =
collects all configs of one expose block (DSL methods write to it)
nil
Class Method Summary collapse
- .disable(message = '') ⇒ Object
- .info(str) ⇒ Object
-
.init(config_path = 'config/toast-api/*', settings_path = 'config/toast-api.rb') ⇒ Object
called once on boot via enigne.rb.
- .logger ⇒ Object
- .raise_config_error(message) ⇒ Object
-
.represent(instance, base_uri = '') ⇒ Object
get the representation (as Hash) by instance (w/o request) base_uri must be passed to be prepended in URIs.
Class Method Details
.disable(message = '') ⇒ Object
72 73 74 75 76 77 |
# File 'lib/toast.rb', line 72 def self.disable ='' info "Disabeling resource exposition due to config errors." info unless .blank? @@expositions.clear end |
.info(str) ⇒ Object
66 67 68 69 70 |
# File 'lib/toast.rb', line 66 def self.info str if Rails.const_defined?('Server') # only on console server puts Toast::Sym+' Toast: '+str end end |
.init(config_path = 'config/toast-api/*', settings_path = 'config/toast-api.rb') ⇒ Object
called once on boot via enigne.rb
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/toast.rb', line 31 def self.init config_path='config/toast-api/*', settings_path='config/toast-api.rb' # clean up Toast.expositions.clear Toast.settings = nil settings = '' # read global settings if File.exists? settings_path open settings_path do |f| settings = f.read end else info "No global settings file found: `#{settings_path}', using defaults" settings_path = '[defaults]' end Toast::ConfigDSL.get_settings settings, settings_path # read configurations config_files = Dir[config_path] if config_files.empty? Toast.raise_config_error "No config files found in `#{config_path}`" else config_files.each do |fname| open fname do |f| config = f.read Toast::ConfigDSL.get_config(config, fname) end end end end |
.logger ⇒ Object
83 84 85 |
# File 'lib/toast.rb', line 83 def self.logger @@logger ||= Logger.new("#{Rails.root}/log/toast.log") end |
.raise_config_error(message) ⇒ Object
79 80 81 |
# File 'lib/toast.rb', line 79 def self.raise_config_error raise ConfigError.new("CONFIG ERROR: #{}") end |
.represent(instance, base_uri = '') ⇒ Object
get the representation (as Hash) by instance (w/o request) base_uri must be passed to be prepended in URIs
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/toast.rb', line 89 def self.represent instance, base_uri = '' # using RequestHelper#represent_one method with a mocked up object obj = Object.new class << obj include Toast::RequestHelpers attr_accessor :base_uri end obj.base_uri = base_uri obj.represent_one(instance, obj.get_config(instance.class) ) end |