Class: FC::Policy
Class Attribute Summary collapse
-
.storages_cache_time ⇒ Object
Returns the value of attribute storages_cache_time.
Attributes inherited from DbBase
Class Method Summary collapse
Instance Method Summary collapse
- #get_copy_storages ⇒ Object
- #get_create_storages ⇒ Object
-
#get_proper_storage_for_copy(size, copy_id = nil, exclude = []) ⇒ Object
get available storage for copy by copy_id and size.
-
#get_proper_storage_for_create(size, exclude = []) ⇒ Object
get available storage for create by size.
Methods inherited from DbBase
create_from_fiels, #delete, find, #initialize, #reload, #save, set_table, where
Constructor Details
This class inherits a constructor from FC::DbBase
Class Attribute Details
.storages_cache_time ⇒ Object
Returns the value of attribute storages_cache_time.
8 9 10 |
# File 'lib/fc/policy.rb', line 8 def storages_cache_time @storages_cache_time end |
Class Method Details
.filter_by_host(host = nil) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/fc/policy.rb', line 12 def self.filter_by_host(host = nil) host = FC::Storage.curr_host unless host self.where.select do |policy| policy.get_create_storages.detect{|storage| storage.host == host} end end |
Instance Method Details
#get_copy_storages ⇒ Object
26 27 28 29 30 31 |
# File 'lib/fc/policy.rb', line 26 def get_copy_storages return @copy_storages_cache if @copy_storages_cache && Time.new.to_i - @get_copy_storages_time.to_i < self.class.storages_cache_time @get_copy_storages_time = Time.new.to_i names = copy_storages.split(',').map{|s| "'#{s}'"}.join(',') @copy_storages_cache = FC::Storage.where("name IN (#{names}) ORDER BY FIELD(name, #{names})") end |
#get_create_storages ⇒ Object
19 20 21 22 23 24 |
# File 'lib/fc/policy.rb', line 19 def get_create_storages return @create_storages_cache if @create_storages_cache && Time.new.to_i - @get_create_storages_time.to_i < self.class.storages_cache_time @get_create_storages_time = Time.new.to_i names = create_storages.split(',').map{|s| "'#{s}'"}.join(',') @create_storages_cache = FC::Storage.where("name IN (#{names}) ORDER BY FIELD(name, #{names})") end |
#get_proper_storage_for_copy(size, copy_id = nil, exclude = []) ⇒ Object
get available storage for copy by copy_id and size
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fc/policy.rb', line 41 def get_proper_storage_for_copy(size, copy_id = nil, exclude = []) storages = get_copy_storages start_storage_index = nil storages.each_with_index do |s, i| start_storage_index = i if copy_id.to_i == s.copy_id.to_i && !exclude.include?(s.name) end storages = storages[start_storage_index..-1]+storages[0..start_storage_index-1] if storages.size > 0 && start_storage_index storages = storages.select do |storage| !exclude.include?(storage.name) && storage.up? && storage.size + size < storage.size_limit end storage = storages.detect{|s| copy_id.to_i == s.copy_id.to_i} storage = storages.detect{|s| copy_id.to_i < s.copy_id.to_i} unless storage storage = storages.first unless storage storage end |
#get_proper_storage_for_create(size, exclude = []) ⇒ Object
get available storage for create by size
34 35 36 37 38 |
# File 'lib/fc/policy.rb', line 34 def get_proper_storage_for_create(size, exclude = []) get_create_storages.detect do |storage| !exclude.include?(storage.name) && storage.up? && storage.size + size < storage.size_limit end end |