goz 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,16 @@
1
1
  = Goz History
2
2
 
3
+ == 2012-04-30 v0.0.3
4
+
5
+ * Added +Goz::Database+
6
+ * Added +Goz::Group+
7
+ * Added +Goz::Service+
8
+ * Added +Goz::User+
9
+
3
10
  == 2012-03-08 v0.0.2
4
11
 
5
12
  * Added +Goz::Cache+
6
13
 
7
-
8
14
  == 2012-03-02 v0.0.1
9
15
 
10
16
  * First public release
@@ -17,7 +17,7 @@
17
17
 
18
18
  == See Also
19
19
 
20
- Goz::Cache, Goz::Logger
20
+ Goz::Cache, Goz::Group, Goz::Logger, Goz::User
21
21
 
22
22
  == Author
23
23
 
@@ -18,11 +18,12 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ['lib']
20
20
 
21
- # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
23
- # s.add_runtime_dependency "rest-client"
24
- s.add_development_dependency 'rake'
25
- s.add_development_dependency 'rdoc'
26
- s.add_development_dependency 'rdoc-readme', '~> 0.1.2'
27
- s.add_development_dependency 'simplecov'
21
+ s.add_runtime_dependency 'sequel'
22
+
23
+ s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'rdoc'
25
+ s.add_development_dependency 'rdoc-readme', '~> 0.1.2'
26
+ s.add_development_dependency 'simplecov'
27
+ s.add_development_dependency 'sqlite3'
28
28
  end
29
+
data/lib/goz.rb CHANGED
@@ -1,7 +1,12 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'goz/cache'
4
+ require 'goz/event'
5
+ require 'goz/event_type'
6
+ require 'goz/group'
4
7
  require 'goz/logger'
8
+ require 'goz/service'
9
+ require 'goz/user'
5
10
  require 'goz/version'
6
11
 
7
12
  #
@@ -24,7 +29,7 @@ require 'goz/version'
24
29
  #
25
30
  # == See Also
26
31
  #
27
- # Goz::Cache, Goz::Logger
32
+ # Goz::Cache, Goz::Group, Goz::Logger, Goz::User
28
33
  #
29
34
  # == Author
30
35
  #
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
- module Goz # :nodoc:
4
- class Cache # :nodoc
3
+ module Goz # :nodoc:
4
+ class Cache # :nodoc:
5
5
 
6
6
  #
7
7
  # = Goz::Cache::HashStore - Hash-based cache implementation.
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'sequel'
4
+ require 'goz/database/migrations'
5
+
6
+ module Goz # :nodoc:
7
+
8
+ #
9
+ # = Goz::Database - Goz persistence layer.
10
+ #
11
+ # == Usage
12
+ #
13
+ # require 'goz/database'
14
+ #
15
+ # # Get Sequel connection
16
+ # Goz::Database.instance do |db|
17
+ # ... do database stuff ...
18
+ # end
19
+ #
20
+ # == Environment
21
+ #
22
+ # If +GOZ_DATABASE_URL+ is not set in your environment, an in-memory SQLite database will be
23
+ # used.
24
+ #
25
+ # == Author
26
+ #
27
+ # blair christensen. <mailto:blair.christensen@gmail.com>
28
+ #
29
+ # == Homepage
30
+ #
31
+ # https://github.com/blairc/goz/
32
+ #
33
+ class Database
34
+
35
+ #
36
+ # Sequel database instance
37
+ #
38
+ DB = ENV['GOZ_DATABASE_URL'] ? Sequel.connect( ENV['GOZ_DATABASE_URL'] ) : Sequel.sqlite
39
+ Goz::Database::Migrations.migrate!
40
+
41
+
42
+ #
43
+ # Get database instance
44
+ #
45
+ def self.instance
46
+ yield DB if block_given?
47
+ DB
48
+ end
49
+
50
+ end
51
+
52
+ end # module Goz
53
+
@@ -0,0 +1,171 @@
1
+ # encoding: utf-8
2
+
3
+ module Goz # :nodoc:
4
+ class Database # :nodoc:
5
+
6
+ #
7
+ # = Goz::Database::Migrations - Database Migrations
8
+ #
9
+ # == See Also
10
+ #
11
+ # Goz::Database
12
+ #
13
+ # == Author
14
+ #
15
+ # blair christensen. <mailto:blair.christensen@gmail.com>
16
+ #
17
+ # == Homepage
18
+ #
19
+ # https://github.com/blairc/goz/
20
+ #
21
+ class Migrations
22
+
23
+ #
24
+ # Perform database migrations.
25
+ #
26
+ def self.migrate!
27
+ Sequel.extension :migration
28
+
29
+ # TODO Split!
30
+ Sequel.migration do
31
+ change do
32
+ DB.create_table(:groups) do
33
+ primary_key :id
34
+ String :display_name, :null => false
35
+ String :identifier, :null => false
36
+ String :name, :null => false
37
+ timestamp :created_at, :null => false
38
+ timestamp :modified_at
39
+ timestamp :synchronized_at
40
+
41
+ index :display_name, :unique => true
42
+ index :identifier, :unique => true
43
+ index :login, :unique => true
44
+ end
45
+ end
46
+ end
47
+
48
+ Sequel.migration do
49
+ change do
50
+ DB.create_table(:services) do
51
+ primary_key :id
52
+ String :name, :null => false
53
+ String :klass, :null => false
54
+ timestamp :created_at, :null => false
55
+ timestamp :modified_at
56
+ timestamp :synchronized_at
57
+
58
+ index :name, :unique => true
59
+ end
60
+ end
61
+ end
62
+
63
+ Sequel.migration do
64
+ change do
65
+ DB.create_table(:users) do
66
+ primary_key :id
67
+ String :email, :null => false
68
+ String :identifier, :null => false
69
+ String :login, :null => false
70
+ String :name, :null => false
71
+ timestamp :created_at, :null => false
72
+ timestamp :modified_at
73
+ timestamp :synchronized_at
74
+
75
+ index :email, :unique => true
76
+ index :identifier, :unique => true
77
+ index :login, :unique => true
78
+ end
79
+ end
80
+ end
81
+
82
+ Sequel.migration do
83
+ change do
84
+ DB.create_table(:admins) do
85
+ foreign_key :group_id, :groups
86
+ foreign_key :user_id, :users
87
+
88
+ index [ :group_id, :user_id ], :unique => true
89
+ end
90
+ end
91
+ end
92
+
93
+ Sequel.migration do
94
+ change do
95
+ DB.create_table(:members) do
96
+ foreign_key :group_id, :groups
97
+ foreign_key :user_id, :users
98
+
99
+ index [ :group_id, :user_id ], :unique => true
100
+ end
101
+ end
102
+ end
103
+
104
+ Sequel.migration do
105
+ change do
106
+ DB.create_table(:group_services) do
107
+ primary_key :id
108
+ foreign_key :group_id, :groups
109
+ foreign_key :service_id, :services
110
+ timestamp :synchronized_at
111
+
112
+ index [ :group_id, :service_id ], :unique => true
113
+ end
114
+ end
115
+ end
116
+
117
+ Sequel.migration do
118
+ change do
119
+ DB.create_table(:event_types) do
120
+ primary_key :id
121
+ String :name
122
+ timestamp :created_at, :null => false
123
+
124
+ index :name, :unique => true
125
+ end
126
+ end
127
+ end
128
+
129
+ Sequel.migration do
130
+ change do
131
+ event_types = DB[:event_types]
132
+ # TODO More to add
133
+ %w( admin_add admin_remove
134
+ group_add group_remove group_sync
135
+ group_service_add group_service_remove group_service_sync
136
+ member_add member_remove
137
+ service_add service_remove service_sync
138
+ user_add user_remove user_sync
139
+ ).each do |type|
140
+ event_types.insert( :name => type, :created_at => Time.now )
141
+ end
142
+ end
143
+ end
144
+
145
+ Sequel.migration do
146
+ change do
147
+ DB.create_table(:events) do
148
+ primary_key :id
149
+ Integer :event_type_id, :null => false
150
+ Integer :group_id, :null => true
151
+ Integer :service_id, :null => true
152
+ Integer :user_id, :null => true
153
+ # TODO Some sort of boolean or enum completion status?
154
+ timestamp :created_at, :null => false
155
+ # TODO Some sort of completed_at timestamp?
156
+
157
+ index :event_type_id
158
+ index :group_id
159
+ index :service_id
160
+ index :user_id
161
+ end
162
+ end
163
+ end
164
+
165
+ end
166
+
167
+ end # class Migrations
168
+
169
+ end # class Database
170
+ end # module Goz
171
+
@@ -0,0 +1,109 @@
1
+ # encoding: utf-8
2
+
3
+ require 'goz/database'
4
+ require 'goz/event_type'
5
+
6
+ module Goz # :nodoc:
7
+
8
+ #
9
+ # = Goz::Event - Goz event
10
+ #
11
+ # == Author
12
+ #
13
+ # blair christensen. <mailto:blair.christensen@gmail.com>
14
+ #
15
+ # == Homepage
16
+ #
17
+ # https://github.com/blairc/goz/
18
+ #
19
+ class Event < Sequel::Model
20
+
21
+ plugin :validation_helpers
22
+
23
+
24
+ #
25
+ # Initialize new (non-persistent) Goz::Event object
26
+ #
27
+ def initialize(*params)
28
+ super
29
+ yield self if block_given?
30
+ self
31
+ end
32
+
33
+ def self.admin_add(group, user)
34
+ self.create( :event_type_id => Goz::EventType::ADMIN_ADD, :group_id => group.id, :user_id => user.id )
35
+ end
36
+
37
+ def self.admin_remove(group, user)
38
+ self.create( :event_type_id => Goz::EventType::ADMIN_REMOVE, :group_id => group.id, :user_id => user.id )
39
+ end
40
+
41
+ def self.group_add(group)
42
+ self.create :event_type_id => Goz::EventType::GROUP_ADD, :group_id => group.id
43
+ end
44
+
45
+ def self.group_remove(group)
46
+ self.create :event_type_id => Goz::EventType::GROUP_REMOVE, :group_id => group.id
47
+ end
48
+
49
+ def self.group_sync(group)
50
+ self.create :event_type_id => Goz::EventType::GROUP_SYNC, :group_id => group.id
51
+ end
52
+
53
+ def self.group_service_add(group, service)
54
+ self.create( :event_type_id => Goz::EventType::GROUP_SERVICE_ADD, :group_id => group.id, :service_id => service.id )
55
+ end
56
+
57
+ def self.group_service_remove(group, service)
58
+ self.create( :event_type_id => Goz::EventType::GROUP_SERVICE_REMOVE, :group_id => group.id, :service_id => service.id )
59
+ end
60
+
61
+ def self.group_service_sync(group, service)
62
+ self.create( :event_type_id => Goz::EventType::GROUP_SERVICE_SYNC, :group_id => group.id, :service_id => service.id )
63
+ end
64
+
65
+ def self.member_add(group, user)
66
+ self.create( :event_type_id => Goz::EventType::MEMBER_ADD, :group_id => group.id, :user_id => user.id )
67
+ end
68
+
69
+ def self.member_remove(group, user)
70
+ self.create( :event_type_id => Goz::EventType::MEMBER_REMOVE, :group_id => group.id, :user_id => user.id )
71
+ end
72
+
73
+ def self.service_add(service)
74
+ self.create( :event_type_id => Goz::EventType::SERVICE_ADD, :service_id => service.id )
75
+ end
76
+
77
+ def self.service_remove(service)
78
+ self.create( :event_type_id => Goz::EventType::SERVICE_REMOVE, :service_id => service.id )
79
+ end
80
+
81
+ def self.service_sync(service)
82
+ self.create( :event_type_id => Goz::EventType::SERVICE_SYNC, :service_id => service.id )
83
+ end
84
+
85
+ def self.user_sync(user)
86
+ self.create( :event_type_id => Goz::EventType::USER_SYNC, :user_id => user.id )
87
+ end
88
+
89
+ #
90
+ # Perform model valiations.
91
+ #
92
+ def validate
93
+ super
94
+ validates_presence :event_type_id
95
+ validates_type Integer, [ :event_type_id, :group_id, :service_id, :user_id ]
96
+ end
97
+
98
+
99
+ private
100
+
101
+ def before_create
102
+ super
103
+ self.created_at ||= Time.now
104
+ end
105
+
106
+ end # class Event
107
+
108
+ end # module Goz
109
+
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ require 'goz/database'
4
+
5
+ module Goz # :nodoc:
6
+
7
+ #
8
+ # = Goz::EventType - Goz event type
9
+ #
10
+ # == Author
11
+ #
12
+ # blair christensen. <mailto:blair.christensen@gmail.com>
13
+ #
14
+ # == Homepage
15
+ #
16
+ # https://github.com/blairc/goz/
17
+ #
18
+ class EventType < Sequel::Model
19
+
20
+ plugin :validation_helpers
21
+
22
+ TYPES = EventType.to_hash(:name, :id)
23
+ TYPES.each_pair { |k, v| const_set k.upcase.to_s, v }
24
+
25
+
26
+ #
27
+ # Perform model valiations.
28
+ #
29
+ def validate
30
+ super
31
+ validates_presence [ :name ]
32
+ validates_type Time, [ :created_at ]
33
+ validates_unique [ :name ]
34
+ end
35
+
36
+
37
+ private
38
+
39
+ def before_create
40
+ super
41
+ self.created_at ||= Time.now
42
+ end
43
+
44
+ end # class EventType
45
+
46
+ end # module Goz
47
+