livedata 0.2.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +1 -1
- data/README +29 -3
- data/Rakefile +1 -1
- data/app/controllers/live_data_controller.rb +39 -0
- data/app/views/live_data/get.xml.erb +0 -0
- data/config/initializers/livedata_init.rb +3 -0
- data/config/routes.rb +5 -0
- data/lib/live_data/engine.rb +4 -0
- data/lib/live_data/thread_watch.rb +1 -1
- data/lib/live_data/user.rb +9 -9
- data/lib/live_data/version.rb +1 -1
- data/lib/live_data.rb +11 -5
- metadata +21 -11
data/MIT-LICENSE
CHANGED
data/README
CHANGED
@@ -2,15 +2,18 @@
|
|
2
2
|
LiveData is a rubygem. This gem is used to implement the applications like chat, live process montior, etc.,
|
3
3
|
|
4
4
|
|
5
|
-
== Installation
|
5
|
+
== Rails2 Installation
|
6
6
|
Step 1 :-
|
7
|
+
Install the gem
|
8
|
+
gem install livedata
|
9
|
+
Step 2 :-
|
7
10
|
Add the livedata gem in config/environment.rb
|
8
11
|
config.gem "livedata"
|
9
|
-
Step
|
12
|
+
Step 3 :-
|
10
13
|
Add the following configuration in the config/environments/development.rb, config/environments/production.rb and config/environments/test.rb
|
11
14
|
config.threadsafe!
|
12
15
|
|
13
|
-
== Example
|
16
|
+
== Rails2 Example
|
14
17
|
Class MainController < ApplicationController
|
15
18
|
|
16
19
|
def get_msg
|
@@ -41,3 +44,26 @@
|
|
41
44
|
Second Tab :-
|
42
45
|
http://localhost:3000/main/send_msg/tester?msg=Hello World
|
43
46
|
|
47
|
+
== Rails3 Installation
|
48
|
+
Step 1 :-
|
49
|
+
Add the following line in the Gemfile
|
50
|
+
gem 'livedata', '>= 0.3.0'
|
51
|
+
Step 2 :-
|
52
|
+
Install the gem, execute the following command
|
53
|
+
bundle install
|
54
|
+
|
55
|
+
== Rails3 Example
|
56
|
+
The livedata gem contain, configurations, controller and routine.
|
57
|
+
Execute the following command to find the services, that already present.
|
58
|
+
rake routes
|
59
|
+
== Run web server
|
60
|
+
rails s -b 0.0.0.0 -p 3000
|
61
|
+
== Browser
|
62
|
+
Open two tabs in the web browser
|
63
|
+
First tab :-
|
64
|
+
http://localhost:3000/live_data/chat/guest.xml
|
65
|
+
Second tab :-
|
66
|
+
http://localhost:3000/live_data/chat/guest/put?message=Hello World
|
67
|
+
|
68
|
+
== Bugs
|
69
|
+
Report the bug on http://github.com/siddick/live_data/issues
|
data/Rakefile
CHANGED
@@ -32,7 +32,7 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
32
32
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
33
33
|
end
|
34
34
|
|
35
|
-
dist_dirs = [ "lib", "test", "examples" ]
|
35
|
+
dist_dirs = [ "lib", "test", "examples", "app", "config" ]
|
36
36
|
|
37
37
|
spec = Gem::Specification.new do |s|
|
38
38
|
s.platform = Gem::Platform::RUBY
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class LiveDataController < ApplicationController
|
2
|
+
DefaultUserId = "guest"
|
3
|
+
DefaultChannelId = "chat"
|
4
|
+
DefaultWaitTime = 15
|
5
|
+
|
6
|
+
def get
|
7
|
+
user_id = params[:user_id] || DefaultUserId
|
8
|
+
channel_id = params[:channel_id] || DefaultChannelId
|
9
|
+
channel = LiveData.get_channel(channel_id) || LiveData.create_channel(channel_id)
|
10
|
+
user = channel.get_user( user_id ) || channel.create_user( user_id )
|
11
|
+
user.set_read_time( ( params[:read_time] || DefaultWaitTime ).to_i )
|
12
|
+
respond_to do |format|
|
13
|
+
format.html {
|
14
|
+
render :text => user.read.to_query
|
15
|
+
}
|
16
|
+
format.xml {
|
17
|
+
render :text => user.read.to_xml
|
18
|
+
}
|
19
|
+
format.yaml {
|
20
|
+
render :text => user.read.to_yaml
|
21
|
+
}
|
22
|
+
format.json {
|
23
|
+
render :text => user.read.to_json
|
24
|
+
}
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def put
|
31
|
+
user_id = params[:user_id] || GestUserId
|
32
|
+
channel_id = params[:channel_id] || DefaultChannelId
|
33
|
+
channel = LiveData.get_channel(channel_id) || LiveData.create_channel(channel_id)
|
34
|
+
user = channel.get_user( user_id ) || channel.create_user( user_id )
|
35
|
+
user.write( params.to_hash )
|
36
|
+
render :text => "OK", :layout => false
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
File without changes
|
data/config/routes.rb
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
Rails::Application.routes.draw do
|
2
|
+
get 'live_data/:channel_id/:user_id' => LiveDataController.action(:get)
|
3
|
+
get 'live_data/:channel_id/:user_id/put(.:format)' => LiveDataController.action(:put)
|
4
|
+
put 'live_data/:channel_id/:user_id(.:format)' => LiveDataController.action(:put)
|
5
|
+
end
|
data/lib/live_data/user.rb
CHANGED
@@ -79,11 +79,11 @@ module LiveData
|
|
79
79
|
# * +yaml_data+ - yaml string
|
80
80
|
def write_yaml( yaml_data )
|
81
81
|
return unless yaml_data and yaml_data.class == String
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
82
|
+
len = [ yaml_data.length ].pack( IntegerPackCode )
|
83
|
+
@lock.synchronize {
|
84
|
+
@write_pipe.write( len )
|
85
|
+
@write_pipe.write( yaml_data )
|
86
|
+
}
|
87
87
|
end
|
88
88
|
|
89
89
|
# Write a Object
|
@@ -98,10 +98,10 @@ module LiveData
|
|
98
98
|
@groups.dup.each{|grp|
|
99
99
|
grp.remove_user( self )
|
100
100
|
}
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
101
|
+
if( @channel )
|
102
|
+
@channel.users.delete( @name )
|
103
|
+
@channel.user_in_groups.delete( @name )
|
104
|
+
end
|
105
105
|
begin
|
106
106
|
@read_pipe.close
|
107
107
|
@write_pipe.close
|
data/lib/live_data/version.rb
CHANGED
data/lib/live_data.rb
CHANGED
@@ -3,15 +3,21 @@
|
|
3
3
|
require 'thread'
|
4
4
|
require 'yaml'
|
5
5
|
|
6
|
-
require 'live_data/version'
|
7
|
-
require 'live_data/channel'
|
8
|
-
require 'live_data/user'
|
9
|
-
require 'live_data/group'
|
10
|
-
require 'live_data/thread_watch'
|
11
6
|
|
12
7
|
module LiveData
|
13
8
|
Channels = {}
|
14
9
|
|
10
|
+
autoload :Version, 'live_data/version'
|
11
|
+
autoload :Channel, 'live_data/channel'
|
12
|
+
autoload :User, 'live_data/user'
|
13
|
+
autoload :Group, 'live_data/group'
|
14
|
+
autoload :ThreadWatch, 'live_data/thread_watch'
|
15
|
+
|
16
|
+
if( defined?(Rails::Engine) )
|
17
|
+
class Engine < Rails::Engine
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
15
21
|
def self.create_channel( name )
|
16
22
|
unless( Channels[name] )
|
17
23
|
Channels[name] = LiveData::Channel.new( name )
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: livedata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Mohammed Siddick. E
|
@@ -14,7 +15,7 @@ autorequire: live_data
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-09-17 00:00:00 +05:30
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -32,16 +33,21 @@ files:
|
|
32
33
|
- install.rb
|
33
34
|
- README
|
34
35
|
- CHANGELOG
|
35
|
-
- lib/live_data/channel.rb
|
36
|
-
- lib/live_data/thread_watch.rb
|
37
|
-
- lib/live_data/group.rb
|
38
|
-
- lib/live_data/user.rb
|
39
|
-
- lib/live_data/version.rb
|
40
36
|
- lib/livedata.rb
|
41
37
|
- lib/live_data.rb
|
42
|
-
-
|
38
|
+
- lib/live_data/version.rb
|
39
|
+
- lib/live_data/group.rb
|
40
|
+
- lib/live_data/channel.rb
|
41
|
+
- lib/live_data/engine.rb
|
42
|
+
- lib/live_data/user.rb
|
43
|
+
- lib/live_data/thread_watch.rb
|
43
44
|
- test/live_data_test.rb
|
44
45
|
- test/test_helper.rb
|
46
|
+
- test/thread_watch_test.rb
|
47
|
+
- app/views/live_data/get.xml.erb
|
48
|
+
- app/controllers/live_data_controller.rb
|
49
|
+
- config/initializers/livedata_init.rb
|
50
|
+
- config/routes.rb
|
45
51
|
has_rdoc: true
|
46
52
|
homepage: http://siddick.github.com/
|
47
53
|
licenses: []
|
@@ -53,23 +59,27 @@ rdoc_options:
|
|
53
59
|
require_paths:
|
54
60
|
- lib
|
55
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
56
63
|
requirements:
|
57
64
|
- - ">="
|
58
65
|
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
59
67
|
segments:
|
60
68
|
- 0
|
61
69
|
version: "0"
|
62
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
63
72
|
requirements:
|
64
73
|
- - ">="
|
65
74
|
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
66
76
|
segments:
|
67
77
|
- 0
|
68
78
|
version: "0"
|
69
79
|
requirements: []
|
70
80
|
|
71
81
|
rubyforge_project:
|
72
|
-
rubygems_version: 1.3.
|
82
|
+
rubygems_version: 1.3.7
|
73
83
|
signing_key:
|
74
84
|
specification_version: 3
|
75
85
|
summary: Handle live data
|