From: Imre Farkas <[email protected]> --- .../provider_selection/provider_selection.rb | 28 +++++++++++++ .../strategies/strict_order/strict_order.rb | 48 ++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/vendor/provider_selection/provider_selection.rb create mode 100644 src/vendor/provider_selection/strategies/strict_order/strict_order.rb
diff --git a/src/vendor/provider_selection/provider_selection.rb b/src/vendor/provider_selection/provider_selection.rb new file mode 100644 index 0000000..8048488 --- /dev/null +++ b/src/vendor/provider_selection/provider_selection.rb @@ -0,0 +1,28 @@ +# +# Copyright 2012 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Require strategies +Dir['vendor/provider_selection/strategies/*/'].each do |path| + strategy_name = File.basename(path) + strategy_lib_path = File.expand_path(File.join(path, "#{strategy_name}.rb")) + ProviderSelection::Base.register_strategy(strategy_name, strategy_lib_path) +end + +# Register view path +#ProviderSelection::Base.add_view_path(File.expand_path(File.join('vendor', 'provider_selection', 'views'))) + +# Extend I18n.load_path +#I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'config', 'locales', '*.yml')] diff --git a/src/vendor/provider_selection/strategies/strict_order/strict_order.rb b/src/vendor/provider_selection/strategies/strict_order/strict_order.rb new file mode 100644 index 0000000..8847e32 --- /dev/null +++ b/src/vendor/provider_selection/strategies/strict_order/strict_order.rb @@ -0,0 +1,48 @@ +# +# Copyright 2012 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +module ProviderSelection + module Strategies + + class StrictOrder + + include ProviderSelection::ChainableStrategy::InstanceMethods + extend ProviderSelection::ChainableStrategy::ClassMethods + + @properties = { + :edit_path => 'pool_provider_selection_provider_priority_groups_path' + } + + def calculate + rank = @strategies.calculate + + if rank.pool.provider_priority_groups.any? + rank.pool.provider_priority_groups.each do |priority_group| + new_priority_group = + ProviderSelection::PriorityGroup. + create_from_active_record(priority_group, + rank.default_priority_group.matches) + rank.priority_groups << new_priority_group if new_priority_group.present? + end + end + + rank + end + + end + + end +end -- 1.7.11.2
