Skip to content

Commit

Permalink
Replace class variable with class_attribute, inherited through subcla…
Browse files Browse the repository at this point in the history
…sses
  • Loading branch information
domcleal committed Sep 30, 2016
1 parent f63d202 commit 4d05ce2
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions app/models/concerns/belongs_to_proxies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ module BelongsToProxies
extend ActiveSupport::Concern

delegate :smart_proxies, :to => :class
included do
class_attribute :smart_proxies_from_model
end

module ClassMethods
def belongs_to_proxy(name, options)
register_smart_proxy(name, options)
smart_proxies_from_model[name] = options
self.smart_proxies_from_model = (smart_proxies_from_model || {}).merge(name => options)
end

def smart_proxies
smart_proxies_from_model.merge(smart_proxies_from_plugins)
(smart_proxies_from_model || {}).merge(smart_proxies_from_plugins)
end

def register_smart_proxy(name, options)
Expand All @@ -20,10 +23,6 @@ def register_smart_proxy(name, options)

private

def smart_proxies_from_model
@smart_proxies_from_model ||= {}
end

def smart_proxies_from_plugins
Foreman::Plugin.all.map {|plugin| plugin.smart_proxies(self) }.inject({}, :merge)
end
Expand Down

0 comments on commit 4d05ce2

Please sign in to comment.