Class: NestedRecord::MacroRecorder
- Inherits:
-
Object
- Object
- NestedRecord::MacroRecorder
- Defined in:
- lib/nested_record/macro_recorder.rb
Constant Summary collapse
- MACROS =
%i[ include attribute def_primary_uuid primary_key has_one_nested has_many_nested subtype subtypes collection_methods validate validates validates! validates_with validates_each validates_absence_of validates_acceptance_of validates_confirmation_of validates_exclusion_of validates_format_of validates_inclusion_of validates_length_of validates_numericality_of validates_presence_of validates_size_of after_initialize before_validation after_validation ].freeze.each do |meth| define_method(meth) do |*args, **kwargs, &block| @macros << [meth, args, kwargs, block] end end
Instance Attribute Summary collapse
-
#macros ⇒ Object
readonly
Returns the value of attribute macros.
Instance Method Summary collapse
- #apply_to(mod_or_class) ⇒ Object
-
#initialize ⇒ MacroRecorder
constructor
A new instance of MacroRecorder.
Constructor Details
#initialize ⇒ MacroRecorder
Returns a new instance of MacroRecorder.
2 3 4 |
# File 'lib/nested_record/macro_recorder.rb', line 2 def initialize @macros = [] end |
Instance Attribute Details
#macros ⇒ Object (readonly)
Returns the value of attribute macros.
6 7 8 |
# File 'lib/nested_record/macro_recorder.rb', line 6 def macros @macros end |
Instance Method Details
#apply_to(mod_or_class) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/nested_record/macro_recorder.rb', line 36 def apply_to(mod_or_class) macros = @macros mod_or_class.module_eval do macros.each do |meth, args, kwargs, block| if kwargs.empty? public_send(meth, *args, &block) else public_send(meth, *args, **kwargs, &block) end end end end |