Class: NestedRecord::MacroRecorder

Inherits:
Object
  • Object
show all
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, &block|
    @macros << [meth, args, block]
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMacroRecorder

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

#macrosObject (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
# 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, block|
      public_send(meth, *args, &block)
    end
  end
end