Class: Mongo::Lock::Configuration
- Inherits:
-
Object
- Object
- Mongo::Lock::Configuration
- Defined in:
- lib/mongo-lock/configuration.rb
Instance Attribute Summary collapse
-
#connections ⇒ Object
Returns the value of attribute connections.
-
#driver ⇒ Object
Returns the value of attribute driver.
-
#expire_in ⇒ Object
Returns the value of attribute expire_in.
-
#frequency ⇒ Object
Returns the value of attribute frequency.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#should_raise ⇒ Object
Returns the value of attribute should_raise.
-
#timeout_in ⇒ Object
Returns the value of attribute timeout_in.
Instance Method Summary collapse
- #add_single_collection_to_collections(options) ⇒ Object
- #array_of_collections(options) ⇒ Object
- #choose_driver(provided_collections) ⇒ Object
- #collection(collection = :default) ⇒ Object
- #collection=(collection) ⇒ Object
- #collections ⇒ Object
- #collections=(collections) ⇒ Object
-
#initialize(defaults, options) {|_self| ... } ⇒ Configuration
constructor
A new instance of Configuration.
- #process_collection_options(options) ⇒ Object
- #set_collections_keep_default(collections) ⇒ Object
- #to_hash ⇒ Object
- #use_registered_collections_if_empty(options) ⇒ Object
Constructor Details
#initialize(defaults, options) {|_self| ... } ⇒ Configuration
Returns a new instance of Configuration.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mongo-lock/configuration.rb', line 14 def initialize defaults, , &block = defaults.merge() [:collections] ||= {} if [:collection] [:collections][:default] = [:collection] end .each_pair do |key,value| self.send(:"#{key}=",value) end yield self if block_given? end |
Instance Attribute Details
#connections ⇒ Object
Returns the value of attribute connections.
5 6 7 |
# File 'lib/mongo-lock/configuration.rb', line 5 def connections @connections end |
#driver ⇒ Object
Returns the value of attribute driver.
12 13 14 |
# File 'lib/mongo-lock/configuration.rb', line 12 def driver @driver end |
#expire_in ⇒ Object
Returns the value of attribute expire_in.
9 10 11 |
# File 'lib/mongo-lock/configuration.rb', line 9 def expire_in @expire_in end |
#frequency ⇒ Object
Returns the value of attribute frequency.
8 9 10 |
# File 'lib/mongo-lock/configuration.rb', line 8 def frequency @frequency end |
#limit ⇒ Object
Returns the value of attribute limit.
6 7 8 |
# File 'lib/mongo-lock/configuration.rb', line 6 def limit @limit end |
#owner ⇒ Object
Returns the value of attribute owner.
10 11 12 |
# File 'lib/mongo-lock/configuration.rb', line 10 def owner @owner end |
#should_raise ⇒ Object
Returns the value of attribute should_raise.
11 12 13 |
# File 'lib/mongo-lock/configuration.rb', line 11 def should_raise @should_raise end |
#timeout_in ⇒ Object
Returns the value of attribute timeout_in.
7 8 9 |
# File 'lib/mongo-lock/configuration.rb', line 7 def timeout_in @timeout_in end |
Instance Method Details
#add_single_collection_to_collections(options) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/mongo-lock/configuration.rb', line 117 def add_single_collection_to_collections if [:collection].is_a? Symbol [:collections] << self.collection([:collection]) elsif [:collection] [:collections] << [:collection] end end |
#array_of_collections(options) ⇒ Object
112 113 114 115 |
# File 'lib/mongo-lock/configuration.rb', line 112 def array_of_collections [:collections] = [:collections].try(:values) || [:collections] || [] end |
#choose_driver(provided_collections) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/mongo-lock/configuration.rb', line 52 def choose_driver provided_collections collections = provided_collections.clone collections = collections.values if collections.is_a? Hash if collections.is_a? Array collection = collections.first collection_class = collections.map{ |x| x.class }.uniq raise MixedCollectionsError.new "Collections must be of the same class" if collection_class.size > 1 else collection = collections end if collection.is_a? Moped::Collection require 'mongo-lock/drivers/moped' self.driver = Mongo::Lock::Drivers::Moped elsif collection.is_a?(Mongo::Collection) or collection.nil? or collection.is_a?(String) or collection.is_a?(Symbol) require 'mongo-lock/drivers/mongo' self.driver = Mongo::Lock::Drivers::Mongo else raise InvalidCollectionError.new "#{collection.class.name} is not a valid collection class" end provided_collections end |
#collection(collection = :default) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/mongo-lock/configuration.rb', line 30 def collection collection = :default collection = collection.to_sym if collection.is_a? String if collection.is_a? Symbol collections[collection] else collection end end |
#collection=(collection) ⇒ Object
26 27 28 |
# File 'lib/mongo-lock/configuration.rb', line 26 def collection= collection collections[:default] = choose_driver collection end |
#collections ⇒ Object
48 49 50 |
# File 'lib/mongo-lock/configuration.rb', line 48 def collections @collections ||= {} end |
#collections=(collections) ⇒ Object
39 40 41 |
# File 'lib/mongo-lock/configuration.rb', line 39 def collections= collections @collections = choose_driver collections end |
#process_collection_options(options) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/mongo-lock/configuration.rb', line 105 def = array_of_collections = add_single_collection_to_collections = use_registered_collections_if_empty end |
#set_collections_keep_default(collections) ⇒ Object
43 44 45 46 |
# File 'lib/mongo-lock/configuration.rb', line 43 def set_collections_keep_default collections collections[:default] = @collections[:default] @collections = collections end |
#to_hash ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/mongo-lock/configuration.rb', line 84 def to_hash { collections: collections, timeout_in: timeout_in, limit: limit, frequency: frequency, expire_in: expire_in, owner: owner, driver: driver, should_raise: should_raise } end |
#use_registered_collections_if_empty(options) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/mongo-lock/configuration.rb', line 126 def use_registered_collections_if_empty if [:collections].empty? [:collections] = self.collections.values end end |