Sha256: dbc0da5e22c5fb2b2c119168aa72c15a3f47dd7268ea2ada74be22215d6a24db

Contents?: true

Size: 774 Bytes

Versions: 7

Compression:

Stored size: 774 Bytes

Contents

class Module
  #  Usage:
  #
  #  class Model
  #    module ModelAspect
  #      declarations do
  #        has_many :aspect_details
  #        validates_presence_of :main_aspect
  #        etc
  #      end
  #    end
  #  end
  def declarations &blk
    unless @declaration_blocks
      @declaration_blocks = []

      def self.included mod
        case mod
          when Class
            @declaration_blocks.each {|b| mod.class_eval &b }
          when Module
            @declaration_blocks.each {|b| mod.declarations &b }
        end
      rescue Exception => ex # When autoloading, you never see real exception unless this rescue
        puts ex.message
        puts ex.backtrace.join("\n")
        raise ex
      end
    end

    @declaration_blocks << blk
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
programmable-ventouse-0.1.0 lib/ventouse/module_declarations.rb
programmable-ventouse-0.1.1 lib/ventouse/module_declarations.rb
programmable-ventouse-0.1.2 lib/ventouse/module_declarations.rb
programmable-ventouse-0.1.3 lib/ventouse/module_declarations.rb
programmable-ventouse-0.1.4 lib/ventouse/module_declarations.rb
programmable-ventouse-0.1.5 lib/ventouse/module_declarations.rb
ventouse-0.1.6 lib/ventouse/module_declarations.rb