Skip to content

Commit

Permalink
Add default priority config
Browse files Browse the repository at this point in the history
  • Loading branch information
kanety committed Jul 25, 2023
1 parent 2b7ee00 commit c5fa4eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/coactive/coaction.rb
Expand Up @@ -3,7 +3,11 @@
module Coactive
class Coaction < Struct.new(:coactor, :name, :options)
def priority
options[:priority] || 1 << 63
options[:priority]
end

def priority=(val)
options[:priority] = val
end
end
end
4 changes: 3 additions & 1 deletion lib/coactive/coactions.rb
Expand Up @@ -24,7 +24,9 @@ def []=(base, name, array)
def coaction(*names, **options)
base = coactive_config.base_class
names.each do |name|
coactions = Coactions[base, name].to_a + [Coaction.new(self, name, options)]
coaction = Coaction.new(self, name, options)
coaction.priority ||= coactive_config.default_priority
coactions = (Coactions[base, name].to_a + [coaction])
Coactions[base, name] = coactions.sort_by.with_index { |coaction, i| [coaction.priority, i] }
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/coactive/config.rb
Expand Up @@ -9,6 +9,7 @@ class Config
use_cache: true,
lookup_superclass_for_object: true,
lookup_superclass_until: ['ActiveRecord::Base', 'ActiveModel::Base'],
default_priority: 1 << 63
}

attr_accessor :data
Expand Down

0 comments on commit c5fa4eb

Please sign in to comment.