Sha256: 8703937ddb6cc11c5e976232585461b5877a1e899f015a9afd06223c36899650

Contents?: true

Size: 901 Bytes

Versions: 19

Compression:

Stored size: 901 Bytes

Contents

#!/usr/bin/env ruby
module Rtt
  class Client
    include DataMapper::Resource

    DEFAULT_NAME = 'default'
    DEFAULT_DESCRIPTION = 'Default Client'

    property :id, Serial
    property :name, String, :required => true, :unique => true, :default => DEFAULT_NAME
    property :description, String, :default => DEFAULT_DESCRIPTION
    property :active, Boolean, :default => false
    has n, :projects #, :through => Resource

    before :create do |client|
      client.active = true if Client.all.length == 0
      true
    end

    def self.default
      first_or_create :active => true
    end

    def self.current_active?
      first :active => true
    end

    def activate
      deactivate_all
      self.active = true
      self.save
      self
    end

    def deactivate_all
      Client.all.each do |client|
        client.active = false
        client.save
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
rtt-0.0.0.47 lib/rtt/client.rb
rtt-0.0.0.46 lib/rtt/client.rb
rtt-0.0.0.45 lib/rtt/client.rb
rtt-0.0.0.44 lib/rtt/client.rb
rtt-0.0.0.43 lib/rtt/client.rb
rtt-0.0.0.42 lib/rtt/client.rb
rtt-0.0.0.41 lib/rtt/client.rb
rtt-0.0.0.39 lib/rtt/client.rb
rtt-0.0.0.38 lib/rtt/client.rb
rtt-0.0.0.37 lib/rtt/client.rb
rtt-0.0.0.36 lib/rtt/client.rb
rtt-0.0.0.35 lib/rtt/client.rb
rtt-0.0.0.33 lib/rtt/client.rb
rtt-0.0.0.32 lib/rtt/client.rb
rtt-0.0.0.31 lib/rtt/client.rb
rtt-0.0.0.28 lib/rtt/client.rb
rtt-0.0.0.27 lib/rtt/client.rb
rtt-0.0.0.26 lib/rtt/client.rb
rtt-0.0.0.25 lib/rtt/client.rb