Sha256: 39f406ff0134dba318d3574020ed5209c57af3a1773de13f6fe336ea332972b0

Contents?: true

Size: 1.3 KB

Versions: 23

Compression:

Stored size: 1.3 KB

Contents

module Her
  module Testing
    module Macros
      module ModelMacros
        # Create a class and automatically inject Her::Model into it
        def spawn_model(klass, options={}, &block)
          super_class = options[:super_class]
          model_type = options[:type] || Her::Model
          new_class = if super_class
                        Class.new(super_class)
                      else
                        Class.new
                      end
          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, new_class)
              submodel.send(:include, model_type)
              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, model_type)
            Object.const_get(klass).class_eval(&block) if block_given?

            @spawned_models << klass.to_sym
          end
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 4 rubygems

Version Path
test_track_rails_client-2.0.0 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-1.3.0 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-1.2.0 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-1.1.0 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-1.0.0 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-0.9.20 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-0.9.19 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-0.9.18 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-0.9.17 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-0.9.16 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-0.9.15 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-0.9.14 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-0.9.13 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-0.9.12 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-0.9.11 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-0.9.10 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-0.9.9 vendor/gems/her/spec/support/macros/model_macros.rb
test_track_rails_client-0.9.8 vendor/gems/her/spec/support/macros/model_macros.rb
her-0.8.2 spec/support/macros/model_macros.rb
her5-0.8.2 spec/support/macros/model_macros.rb