Class: Breadboard
- Inherits:
-
Object
- Object
- Breadboard
- Defined in:
- lib/breadboard/breadboard.rb
Defined Under Namespace
Classes: EnvironmentUnknownError
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #environment ⇒ Object
-
#initialize(config_yml) ⇒ Breadboard
constructor
A new instance of Breadboard.
- #service_for(klass) ⇒ Object
Constructor Details
#initialize(config_yml) ⇒ Breadboard
Returns a new instance of Breadboard.
6 7 8 |
# File 'lib/breadboard/breadboard.rb', line 6 def initialize(config_yml) @config = YAML.load config_yml end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
2 3 4 |
# File 'lib/breadboard/breadboard.rb', line 2 def config @config end |
Instance Method Details
#environment ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/breadboard/breadboard.rb', line 10 def environment begin RAILS_ENV rescue raise EnvironmentUnknownError, "RAILS_ENV environment unknown" end end |
#service_for(klass) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/breadboard/breadboard.rb', line 18 def service_for(klass) serv = nil while serv.nil? && klass != ActiveResource::Base do table = klass.to_s.tableize.singularize serv = (@config[table][environment] rescue nil) || (@config[table]['all'] rescue nil) || nil klass = klass.superclass end serv || (@config['default'][environment] rescue nil) || (@config['default']['all'] rescue nil) || '' end |