module LinkedRails::Model::Enhancements::ClassMethods
Public Instance Methods
enhance(enhancement, opts = {})
click to toggle source
Adds an enhancement to a model and includes the Model
module.
# File lib/linked_rails/model/enhancements.rb, line 19 def enhance(enhancement, opts = {}) initialize_enhancements already_included = enhanced_with?(enhancement) self.enhancements[enhancement] = opts return if already_included enhance_routing(enhancement) if enhancement.const_defined?(:Routing) && enhanced_with?(enhancement, :Routing) include enhancement::Model if enhancement.const_defined?(:Model) && enhanced_with?(enhancement, :Model) end
enhanced_with?(enhancement, const = nil)
click to toggle source
# File lib/linked_rails/model/enhancements.rb, line 30 def enhanced_with?(enhancement, const = nil) return false unless self.enhancements.key?(enhancement) return true if const.nil? opts = self.enhancements[enhancement] return opts[:only].include?(const) if opts.key?(:only) !opts.key?(:except) || !opts[:except].include?(const) end
enhancement_modules(const)
click to toggle source
# File lib/linked_rails/model/enhancements.rb, line 41 def enhancement_modules(const) enhancements .select { |enhancement, _opts| enhancement.const_defined?(const) && enhanced_with?(enhancement, const) } .map { |enhancement, _opts| enhancement.const_get(const) } end
Private Instance Methods
enhance_routing(enhancement)
click to toggle source
# File lib/linked_rails/model/enhancements.rb, line 49 def enhance_routing(enhancement) LinkedRails::Enhancements::RouteConcerns.add_concern(enhancement) end
initialize_enhancements()
click to toggle source
# File lib/linked_rails/model/enhancements.rb, line 53 def initialize_enhancements return if enhancements && method(:enhancements).owner == singleton_class self.enhancements = superclass.try(:enhancements)&.dup || {} end