Module: LinkedRails::Model::Enhancements::ClassMethods
- Defined in:
- lib/linked_rails/model/enhancements.rb
Instance Method Summary collapse
-
#enhance(enhancement, **opts) ⇒ Object
Adds an enhancement to a model and includes the Model module.
- #enhanced_with?(enhancement, const = nil) ⇒ Boolean
- #enhancement_modules(const) ⇒ Object
Instance Method Details
#enhance(enhancement, **opts) ⇒ Object
Adds an enhancement to a model and includes the Model module.
19 20 21 22 23 24 25 26 27 |
# 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 include enhancement::Model if enhancement.const_defined?(:Model) && enhanced_with?(enhancement, :Model) end |
#enhanced_with?(enhancement, const = nil) ⇒ Boolean
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/linked_rails/model/enhancements.rb', line 29 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) ⇒ Object
40 41 42 43 44 |
# File 'lib/linked_rails/model/enhancements.rb', line 40 def enhancement_modules(const) enhancements .select { |enhancement, _opts| enhancement.const_defined?(const) && enhanced_with?(enhancement, const) } .map { |enhancement, _opts| enhancement.const_get(const) } end |