Class: Goz::Service

Inherits:
Sequel::Model
  • Object
show all
Includes:
Comparable
Defined in:
lib/goz/service.rb,
lib/goz/service/base.rb,
lib/goz/service/fake_service.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Base, FakeService

Constant Summary collapse

TAG =
self.name

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_name(name) ⇒ Object

Find Goz::Service by name or return nil



89
90
91
92
# File 'lib/goz/service.rb', line 89

def self.find_by_name(name)
  Goz::Logger.debug TAG, "find_by_name( name=#{name} )"
  self.find :name => name
end

Instance Method Details

#<=>(other) ⇒ Object

Compare equality.



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/goz/service.rb', line 46

def <=>(other)
  if    self.name   < other.name  ||
        self.klass  < other.klass
    -1
  elsif self.name   > other.name  ||
        self.klass  > other.klass
    1
  else
    0
  end
end

#configuration(configuration = {}) ⇒ Object

XXX



59
60
61
# File 'lib/goz/service.rb', line 59

def configuration( configuration = {} )
  klass_instance.configuration configuration
end

#create(g) ⇒ Object

XXX



72
73
74
75
# File 'lib/goz/service.rb', line 72

def create(g)
  Goz::Logger.debug TAG, "#create( group.name=#{g.name} )"
  klass_instance.create g
end

#destroy(g) ⇒ Object



77
78
79
80
# File 'lib/goz/service.rb', line 77

def destroy(g)
  Goz::Logger.debug TAG, "#destroy( group.name=#{g.name} )"
  klass_instance.destroy g
end

#klass_instanceObject



63
64
65
66
67
68
69
# File 'lib/goz/service.rb', line 63

def klass_instance
  unless @k
    require self.klass.underscore
    @k = self.klass.constantize
  end
  return @k
end

#sync(force = false) ⇒ Object



108
109
110
111
112
113
114
115
# File 'lib/goz/service.rb', line 108

def sync(force = false)
  Goz::Logger.debug TAG, "#sync( force=#{force} )"
  self.groups.each { |g| self.klass_instance.sync_group g, self }
  self.synchronized_at = Time.now
  self.save
  Goz::Event.service_sync self
  return true
end

#sync_group(g) ⇒ Object

Synchronize service with external data sources (if relevant).



97
98
99
100
101
102
103
104
105
106
# File 'lib/goz/service.rb', line 97

def sync_group(g) # XXX
  Goz::Logger.debug TAG, "#sync_group( group.name=#{g.name} )"
  if klass_instance.sync_group g, self
    self.synchronized_at = Time.now # TODO GroupService
    self.save                       # TODO GroupService
    Goz::Event.service_sync(self)   # TODO GroupService
    return true
  end
  false
end

#to_sObject



82
83
84
# File 'lib/goz/service.rb', line 82

def to_s
  "name=#{ self.name } klass=#{ self.klass }"
end

#validateObject

Perform model valiations.



120
121
122
123
124
# File 'lib/goz/service.rb', line 120

def validate
  super
  validates_presence  [ :name, :klass ]
  validates_type      Time, [ :created_at, :modified_at, :synchronized_at ]
end