Sha256: 573cb01abf4bd0a8fd189c9d5b891b28498feba1c06971325cf141aff19e9576

Contents?: true

Size: 1002 Bytes

Versions: 2

Compression:

Stored size: 1002 Bytes

Contents

require 'caruby/resource'

module CaRuby
  # The Annotatable module marks a domain class as an anchor which holds at least one annotation attribute.
  module Annotatable
    include Resource

    # Dynamically creates a new annotation reference method with the given symbol if symbol is the camelized form of a
    # class in one of the Annotatable class's annotation modules.
    def method_missing(symbol, *args)
      name = symbol.to_s
      # remove trailing assignment = if present
      name.chop! if name =~ /=$/
      # the class with the camelized form of the name
      klass = self.class.annotation_class(name.camelize)
      # delegate to super to print an error if no class
      super if klass.nil?
      # add the annotation attribute
      klass.add_annotation(self.class)
      raise NotImplementedError.new("#{self.class.qp} annotation method not created: #{symbol}") unless respond_to?(symbol)
      #call the annotation attribute method
      send(symbol, *args)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
caruby-core-1.4.2 lib/caruby/domain/annotatable.rb
caruby-core-1.4.1 lib/caruby/domain/annotatable.rb