Sha256: fc1ad631613c9fda6f876614fdee4781284e0cc8ab69fba66a633d1c877dabb3

Contents?: true

Size: 1.8 KB

Versions: 13

Compression:

Stored size: 1.8 KB

Contents

module ActiveMocker
module MockClassMethods

  def mock_instance_method(method, &block)
    model_instance_methods[method] = block
  end

  def mock_class_method(method, &block)
    model_class_methods[method] = block
  end

  def column_names
    schema_attributes_template
  end

  private

  def delegate_to_model_instance(method, *args)
    model_class_instance.send(method, *args)
  end

  def delegate_to_model_class(method, *args)
    model_class.send(method, *args)
  end

  def model_class_methods
    @model_class_methods ||= HashWithIndifferentAccess.new
  end

  def model_methods_template
    @model_methods_template ||= HashWithIndifferentAccess.new
  end

  def schema_attributes_template
    @schema_attributes_template ||= HashWithIndifferentAccess.new
  end

  def model_class
    @model_class
  end

  def model_class_instance
    @model_class_instance ||= model_class.new
  end

  def attribute_names
    @attribute_names
  end

  def attribute_names=(attributes)
    @attribute_names = attributes.map{|a| a.to_sym}
  end

  def attribute_template
    return @attribute_template unless @attribute_template.nil?
    @attribute_template = HashWithIndifferentAccess.new
    attribute_names.each {|a| @attribute_template[a] = nil}
    return @attribute_template
  end

  def association_names
    @association_names
  end

  def association_names=(associations)
    @association_names = associations.map{|a| a.to_sym}
  end

  def association_template
    return @association_template unless @association_template.nil?
    @association_template = HashWithIndifferentAccess.new
    association_names.each {|a| @association_template[a] = nil}
    return @association_template
  end

  public
  def is_implemented(val, method)
    raise "#{method} is not Implemented for Class: #{name}" if val == :not_implemented
  end

end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
active_mocker-1.2 lib/active_mocker/mock_class_methods.rb
active_mocker-1.2.pre.11 lib/active_mocker/mock_class_methods.rb
active_mocker-1.2.pre.10 lib/active_mocker/mock_class_methods.rb
active_mocker-1.2.pre.9 lib/active_mocker/mock_class_methods.rb
active_mocker-1.2.pre.8 lib/active_mocker/mock_class_methods.rb
active_mocker-1.2.pre.7 lib/active_mocker/mock_class_methods.rb
active_mocker-1.2.pre.6 lib/active_mocker/mock_class_methods.rb
active_mocker-1.2.pre.5 lib/active_mocker/mock_class_methods.rb
active_mocker-1.2.pre.4 lib/active_mocker/mock_class_methods.rb
active_mocker-1.2.pre.3 lib/active_mocker/mock_class_methods.rb
active_mocker-1.2.pre.2 lib/active_mocker/mock_class_methods.rb
active_mocker-1.2.pre.1 lib/active_mocker/mock_class_methods.rb
active_mocker-1.2.pre lib/active_mocker/mock_class_methods.rb