Class: Goz::Service
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Goz::Service
- 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
-
.find_by_name(name) ⇒ Object
Find Goz::Service by name or return
nil
.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compare equality.
-
#configuration(configuration = {}) ⇒ Object
XXX.
-
#create(g) ⇒ Object
XXX.
- #destroy(g) ⇒ Object
- #klass_instance ⇒ Object
- #sync(force = false) ⇒ Object
-
#sync_group(g) ⇒ Object
Synchronize service with external data sources (if relevant).
- #to_s ⇒ Object
-
#validate ⇒ Object
Perform model valiations.
Class Method Details
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_instance ⇒ Object
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_s ⇒ Object
82 83 84 |
# File 'lib/goz/service.rb', line 82 def to_s "name=#{ self.name } klass=#{ self.klass }" end |
#validate ⇒ Object
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 |