Sha256: 5cfb3143523ee3c7888a5321e5bb5095b497cccd6e7dab521190eac398b406c3

Contents?: true

Size: 679 Bytes

Versions: 3

Compression:

Stored size: 679 Bytes

Contents

module Aid
  module Inheritable
    def self.included(klass)
      klass.instance_eval do
        extend ClassMethods

        def self.inherited(subklass)
          Aid::Script.script_classes << subklass
        end
      end
    end

    module ClassMethods
      def script_classes
        @script_classes ||= []
      end

      def reset_script_classes!
        @scripts = nil
        @script_classes = []
      end

      def scripts
        @scripts ||= load_scripts_deferred
      end

      def load_scripts_deferred
        script_classes.reduce(Hash.new) do |result, klass|
          result[klass.name] = klass
          result
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aid-0.1.3 lib/aid/inheritable.rb
aid-0.1.2 lib/aid/inheritable.rb
aid-0.1.1 lib/aid/inheritable.rb