require 'active_mocker/mock_requires' Object.send(:remove_const, "#{model_name}Mock") if false && ActiveMocker.class_exists?("#{model_name}Mock") class <%= class_name %> < ::ActiveHash::Base include ActiveMocker::ActiveHash::ARApi include ActiveMocker::MockInstanceMethods extend ActiveMocker::MockClassMethods def self.column_names <%= attribute_names %> end def self.association_names @association_names = <%= association_names.map{|a| a.to_sym} %> end def self.attribute_names @attribute_names = <%= attribute_names.map{|a| a.to_sym} %> end <% attributes.each do |meth| %> def <%= meth %> attributes['<%= meth %>'] end def <%= meth %>=(val) attributes['<%= meth %>'] = val end <% end %> <% single_associations.each do |meth| %> def <%= meth %> associations['<%= meth %>'] end def <%= meth %>=(val) associations['<%= meth %>'] = val end <% end %> <% collection_associations.each do |meth| %> def <%= meth %> associations['<%= meth %>'] end def <%= meth %>=(val) associations['<%= meth %>'] = ActiveMocker::CollectionAssociation.new(val) end <% end %> def self.model_instance_methods return @model_instance_methods if @model_instance_methods @model_instance_methods = {}<% model_instance_methods.each do |key, value| %> @model_instance_methods[:<%= key %>] = :not_implemented <% end %> @model_instance_methods end def self.model_class_methods return @model_class_methods if @model_class_methods @model_class_methods = {}<% model_class_methods.each do |key, value| %> @model_class_methods[:<%= key %>] = :not_implemented <% end %> @model_class_methods end <% instance_methods.each do |method| %> def <%= method.method %>(<%= method.params %>) block = model_instance_methods[<%= method.method.inspect %>] self.class.is_implemented(block, "#<%= method.method %>") instance_exec(*[<%= method.params_pass %>], &block) end <% end %> <% class_methods.each do |method| %> def self.<%= method.method %>(<%= method.params %>) block = model_class_methods[<%= method.method.inspect %>] is_implemented(block, "::<%= method.method %>") instance_exec(*[<%= method.params_pass %>], &block) end <% end %> end