Sha256: 9ff68689f616a8be14ae536102a636b9350b52ca77777566940b6a24e5934539
Contents?: true
Size: 1.03 KB
Versions: 15
Compression:
Stored size: 1.03 KB
Contents
module Her module Testing module Macros module ModelMacros # Create a class and automatically inject Her::Model into it def spawn_model(klass, &block) if klass =~ /::/ base, submodel = klass.split(/::/).map{ |s| s.to_sym } Object.const_set(base, Module.new) unless Object.const_defined?(base) Object.const_get(base).module_eval do remove_const submodel if constants.map(&:to_sym).include?(submodel) submodel = const_set(submodel, Class.new) submodel.send(:include, Her::Model) submodel.class_eval(&block) if block_given? end @spawned_models << base else Object.instance_eval { remove_const klass } if Object.const_defined?(klass) Object.const_set(klass, Class.new).send(:include, Her::Model) Object.const_get(klass).class_eval(&block) if block_given? @spawned_models << klass.to_sym end end end end end end
Version data entries
15 entries across 15 versions & 2 rubygems