Project

General

Profile

Revision e702df84

Added by Dmitri Dolguikh over 9 years ago

added IoC way of configuring of runcible

View differences:

lib/runcible/base.rb
24 24
require 'rest_client'
25 25
require 'oauth'
26 26
require 'json'
27
require 'thread'
27 28

  
28 29

  
29 30
module Runcible
30 31
  class Base
31

  
32
    
32 33
    def initialize(config={})
34
      @mutex = Mutex.new
33 35
      @config = config
34 36
    end
35 37

  
38
    def lazy_config=(blk)
39
      @mutex.synchronize { @lazy_config = blk }
40
    end
41

  
36 42
    def config
37
      if defined?(@config)
43
      @mutex.synchronize do
44
        @config = @lazy_config.call if defined?(@lazy_config)
45
        raise Runcible::ConfigurationUndefinedError, Runcible::ConfigurationUndefinedError.message unless @config
38 46
        @config
39
      else
40
        raise Runcible::ConfigurationUndefinedError, Runcible::ConfigurationUndefinedError.message
41 47
      end
42 48
    end
43 49

  

Also available in: Unified diff