Sha256: 52c67f9562150de6b3da051d2b3fa319e1803aace4a9ed641888143a1bd6fe8b

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES

  #
  # SCMs
  #
  # This example may look stupid (I am sure it is),
  # but it is way better than foobars and easier to read/add cases
  # compared to gardening examples because every software engineer has idea
  # about SCMs and not every software engineer does gardening often.
  #

  class ScmOperation
    include DataMapper::Resource

    #
    # Property
    #

    property :id,                 Serial

    # operation name
    property :name,               String,  :auto_validation => false

    property :committer_name,     String,  :auto_validation => false, :default => "Just another Ruby hacker"
    property :author_name,        String,  :auto_validation => false, :default => "Just another Ruby hacker"
    property :network_connection, Boolean, :auto_validation => false
    property :message,            Text,    :auto_validation => false
    property :clean_working_copy, Boolean, :auto_validation => false

    #
    # Validations
    #

    validates_present :name
  end
  ScmOperation.auto_migrate!


  class SubversionOperation < ScmOperation
    #
    # Validations
    #

    validates_present :network_connection, :when => [:committing, :log_viewing]
  end

  SubversionOperation.auto_migrate!


  class GitOperation < ScmOperation
    #
    # Validations
    #

    validates_present :author_name, :committer_name, :when => :committing

    validates_present :message,            :when => :committing
    validates_present :network_connection, :when => [:pushing, :pulling], :message => {
      :pushing => "though git is advanced, it cannot push without network connectivity",
      :pulling => "you must have network connectivity to pull from others"
    }
    validates_present :clean_working_copy, :when => :pulling
  end


  GitOperation.auto_migrate!
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dm-validations-0.10.1 spec/fixtures/scm_operation.rb
dm-validations-0.10.0 spec/fixtures/scm_operation.rb