Project

General

Profile

« Previous | Next » 

Revision 38964973

Added by Dominic Cleal over 6 years ago

Fixes #20957 - Replace alias_method_chain with Module prepend

Deprecated in Rails 5.0 and will be removed in 5.1. Some instances of
classes overwriting existing methods can be handled with `super`, other
concerns or modules are changed to use prepend instead of include.

Note: no ActiveSupport::Concern support for prepends, so load class
methods the pure Ruby way.

View differences:

app/models/subnet.rb
BOOT_MODES = {:static => N_('Static'), :dhcp => N_('DHCP')}
include Authorizable
include Foreman::STI
prepend Foreman::STI
extend FriendlyId
friendly_id :name
include Taxonomix
......
end
# This casts Subnet to Subnet::Ipv4 if no type is set
def new_with_default_type(*attributes, &block)
def new(*attributes, &block)
type = attributes.first.with_indifferent_access.delete(:type) if attributes.first.is_a?(Hash)
return Subnet::Ipv4.new_without_cast(*attributes, &block) if self == Subnet && type.nil?
new_without_default_type(*attributes, &block)
return Subnet::Ipv4.new(*attributes, &block) if self == Subnet && type.nil?
super
end
alias_method_chain :new, :default_type
# allows to create a specific subnet class based on the network_type.
# network_type is more user friendly than the class names

Also available in: Unified diff