Sha256: 78f590c0441ad9961a4b27f8f82e49a20957ce8620425e2454ead85f0954b028

Contents?: true

Size: 651 Bytes

Versions: 37

Compression:

Stored size: 651 Bytes

Contents

class CustomClass
  attr_reader :name
  
  def initialize(name)
    @name = name
  end
  
  def ==(other)
    other.is_a?(self.class) && name == other.name
  end
  
  def to_mongo
    { :name => name }
  end
  
  def self.from_mongo(hash)
    new(hash[:name])
  end
  
  def self.cast(value)
    new(value.to_s)
  end
end

class CustomClassWithDefault < CustomClass
  def self.mongomodel_default(doc)
    new("Custom class default")
  end
end

class CustomClassWithAccessors < CustomClass
  def self.mongomodel_accessors(property)
    Module.new do
      define_method(:custom_accessor) do
        "Custom accessor method"
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
mongomodel-0.3.2 spec/support/models.rb
mongomodel-0.3.1 spec/support/models.rb
mongomodel-0.3.0 spec/support/models.rb
mongomodel-0.2.20 spec/support/models.rb
mongomodel-0.2.19 spec/support/models.rb
mongomodel-0.2.18 spec/support/models.rb
mongomodel-0.2.17 spec/support/models.rb
mongomodel-0.2.16 spec/support/models.rb
mongomodel-0.2.15 spec/support/models.rb
mongomodel-0.2.14 spec/support/models.rb
mongomodel-0.2.13 spec/support/models.rb
mongomodel-0.2.12 spec/support/models.rb
mongomodel-0.2.11 spec/support/models.rb
mongomodel-0.2.10 spec/support/models.rb
mongomodel-0.2.9 spec/support/models.rb
mongomodel-0.2.8 spec/support/models.rb
mongomodel-0.2.7 spec/support/models.rb