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

Version Path
her-0.7.6 spec/support/macros/model_macros.rb
her-0.7.5 spec/support/macros/model_macros.rb
her-0.7.4 spec/support/macros/model_macros.rb
herr-0.7.3 spec/support/macros/model_macros.rb
her-0.7.3 spec/support/macros/model_macros.rb
her-0.7.2 spec/support/macros/model_macros.rb
her-0.7.1 spec/support/macros/model_macros.rb
her-0.7 spec/support/macros/model_macros.rb
her-0.6.8 spec/support/macros/model_macros.rb
her-0.6.7 spec/support/macros/model_macros.rb
her-0.6.6 spec/support/macros/model_macros.rb
her-0.6.5 spec/support/macros/model_macros.rb
her-0.6.4 spec/support/macros/model_macros.rb
her-0.6.3 spec/support/macros/model_macros.rb
her-0.6.2 spec/support/macros/model_macros.rb