Module: ConcernedWithZeitwerk

Defined in:
lib/concerned_with_zeitwerk.rb,
lib/concerned_with_zeitwerk/version.rb

Overview

concerned_with method can be used for code spliting in model files. By creating concern such as Callbacks, Associations, Validations, etc., inside the model folder

foo/

associations.rb
callbacks.rb
validations.rb

foo.rb

and include those files in the model file as shown below :

class Foo

concerned_with :associations, :validations, :callbacks

end

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#concerned_with(*concerns) ⇒ Object

This method will include concern in below fashion include Foo::Associations



22
23
24
25
26
27
28
# File 'lib/concerned_with_zeitwerk.rb', line 22

def concerned_with(*concerns)
  concerns.each do |concern|
    module_name = "#{name}::#{concern.to_s.camelize}"
    concern_module = const_get(module_name)
    include concern_module
  end
end