c3s 0.4.6 → 0.4.10

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/Manifest CHANGED
@@ -1,5 +1,7 @@
1
1
  README.rdoc
2
2
  Rakefile
3
+ c3s
4
+ c3s.gemspec
3
5
  lib/c3s.rb
4
6
  lib/c3s_logger.rb
5
7
  lib/component.rb
@@ -12,4 +14,5 @@ lib/pubsub/nodetracker.rb
12
14
  lib/pubsub/publisher.rb
13
15
  lib/pubsub/subscriber.rb
14
16
  lib/republisher.rb
17
+ lib/version.rb
15
18
  Manifest
data/Rakefile CHANGED
@@ -1,9 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
+ require 'lib/version'
4
5
 
5
- Echoe.new('c3s', '0.4.6') do |p|
6
- p.description = "C3s library gem."
6
+ Echoe.new('c3s', C3s::VERSION.to_s) do |p|
7
+ p.description = C3s::DESCRIPTION
7
8
  p.url = "http://github.com/rikas/c3s"
8
9
  p.author = "Ricardo Otero"
9
10
  p.email = "oterosantos@gmail.com"
data/c3s ADDED
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This is the command used to run the component
4
+
5
+ require 'rubygems'
6
+
7
+ # Check for gem versions
8
+ gem 'c3s', '>=0.3.1'
9
+ gem 'xmpp4r', '>=0.5'
10
+
11
+ require 'c3s'
12
+ require 'pathname'
13
+
14
+ PROVIDERS_DIR = File.join(ENV['HOME'], "ptcb", "code", "providers")
15
+
16
+ def usage
17
+ puts "Usage: provider [provider_dir]"
18
+ puts ""
19
+ puts "Available providers: #{available_providers}"
20
+ puts ""
21
+ exit
22
+ end
23
+
24
+ def available_providers
25
+ available_providers = []
26
+ Dir.glob(File.join(PROVIDERS_DIR, "*")) do |dir|
27
+ next unless File.directory?(dir)
28
+ conf = File.join(dir, "component.yml")
29
+ path = Pathname.new(dir)
30
+ available_providers << path.basename if File.exist?(conf)
31
+ end
32
+ available_providers.join(", ")
33
+ end
34
+
35
+ args = ARGV
36
+ if (args.size!=1)
37
+ usage
38
+ else
39
+ provider = File.join(PROVIDERS_DIR, args.last)
40
+ if (!File.directory?(provider))
41
+ puts "Couldn't find '#{args.last}' provider"
42
+ exit
43
+ end
44
+ end
45
+
46
+ # Set process name to provider
47
+ $0 = args.last
48
+
49
+ # Set the dir variables
50
+ C3S_COMPONENT_DIR = File.join(PROVIDERS_DIR, args.last)
51
+ C3S_LIB_DIR = File.join(C3S_COMPONENT_DIR, 'lib')
52
+ C3S_LOG_DIR = File.join(C3S_COMPONENT_DIR, 'logs')
53
+
54
+ # Power to the requires
55
+ $:.unshift C3S_COMPONENT_DIR
56
+ $:.unshift C3S_LIB_DIR
57
+ $:.unshift File.join(C3S_LIB_DIR, args.last)
58
+
59
+ require 'lib/runner'
data/c3s.gemspec CHANGED
@@ -2,24 +2,23 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{c3s}
5
- s.version = "0.4.6"
5
+ s.version = "0.4.10"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ricardo Otero"]
9
- s.date = %q{2010-11-22}
10
- s.description = %q{C3s library gem.}
9
+ s.date = %q{2011-03-09}
10
+ s.description = %q{C3S 0.4.10 - Library to make context entities on C3S project.}
11
11
  s.email = %q{oterosantos@gmail.com}
12
- s.extra_rdoc_files = ["README.rdoc", "lib/c3s.rb", "lib/c3s_logger.rb", "lib/component.rb", "lib/component_connection.rb", "lib/configreader.rb", "lib/databaseadapter.rb", "lib/model.rb", "lib/pubsub/node.rb", "lib/pubsub/nodetracker.rb", "lib/pubsub/publisher.rb", "lib/pubsub/subscriber.rb", "lib/republisher.rb"]
13
- s.files = ["README.rdoc", "Rakefile", "c3s.gemspec", "lib/c3s.rb", "lib/c3s_logger.rb", "lib/component.rb", "lib/component_connection.rb", "lib/configreader.rb", "lib/databaseadapter.rb", "lib/model.rb", "lib/pubsub/node.rb", "lib/pubsub/nodetracker.rb", "lib/pubsub/publisher.rb", "lib/pubsub/subscriber.rb", "lib/republisher.rb", "Manifest"]
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/c3s.rb", "lib/c3s_logger.rb", "lib/component.rb", "lib/component_connection.rb", "lib/configreader.rb", "lib/databaseadapter.rb", "lib/model.rb", "lib/pubsub/node.rb", "lib/pubsub/nodetracker.rb", "lib/pubsub/publisher.rb", "lib/pubsub/subscriber.rb", "lib/republisher.rb", "lib/version.rb"]
13
+ s.files = ["README.rdoc", "Rakefile", "c3s", "c3s.gemspec", "lib/c3s.rb", "lib/c3s_logger.rb", "lib/component.rb", "lib/component_connection.rb", "lib/configreader.rb", "lib/databaseadapter.rb", "lib/model.rb", "lib/pubsub/node.rb", "lib/pubsub/nodetracker.rb", "lib/pubsub/publisher.rb", "lib/pubsub/subscriber.rb", "lib/republisher.rb", "lib/version.rb", "Manifest"]
14
14
  s.homepage = %q{http://github.com/rikas/c3s}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "C3s", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = %q{c3s}
18
- s.rubygems_version = %q{1.3.7}
19
- s.summary = %q{C3s library gem.}
18
+ s.rubygems_version = %q{1.4.1}
19
+ s.summary = %q{C3S 0.4.10 - Library to make context entities on C3S project.}
20
20
 
21
21
  if s.respond_to? :specification_version then
22
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
22
  s.specification_version = 3
24
23
 
25
24
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
data/lib/c3s.rb CHANGED
@@ -17,6 +17,7 @@ require 'model'
17
17
  require 'configreader'
18
18
  require 'databaseadapter'
19
19
  require 'c3s_logger'
20
+ require 'version'
20
21
 
21
22
  begin
22
23
  require 'xmpp4r'
@@ -27,15 +28,13 @@ rescue Exception => e
27
28
  end
28
29
 
29
30
  module C3s
30
- VERSION = "0.4.6"
31
-
32
31
  def self.included(base)
33
32
  base.extend ClassMethods
34
33
  end
35
-
34
+
36
35
  def ensure_unique(name)
37
36
  begin
38
37
  self[name] = yield
39
38
  end while self.class.exists?(name => self[name])
40
39
  end
41
- end
40
+ end
data/lib/model.rb CHANGED
@@ -12,7 +12,7 @@ module C3sModel
12
12
  end
13
13
  attr_hash
14
14
  end
15
-
15
+
16
16
  def attributes=(att, guard_protected_attributes)
17
17
  att.each do |key, val|
18
18
  self.attrs << key.to_s
@@ -23,7 +23,7 @@ module C3sModel
23
23
  end
24
24
  base.extend(ClassMethods)
25
25
  end
26
-
26
+
27
27
  module ClassMethods
28
28
  def attribute(attribute)
29
29
  self.attrs ||= []
@@ -31,27 +31,27 @@ module C3sModel
31
31
  attr_accessor attribute
32
32
  end
33
33
  end
34
-
34
+
35
35
  ##
36
36
  # Attributes ignored and not included on model xml by default
37
37
  IGNORE_ATTR = ["created_at", "updated_at", "id", "jid"]
38
-
38
+
39
39
  def is_AR?
40
40
  end
41
-
41
+
42
42
  ##
43
43
  # Updates multiple attributes at once
44
44
  # attributes:: [Hash] the attributes hash
45
45
  def update_attributes(attributes={})
46
46
  self.send(:attributes=, attributes, false)
47
47
  end
48
-
48
+
49
49
  ##
50
50
  # Returns the class name for this model without module name
51
51
  def _class_name
52
52
  @class_name ||= self.class.name.split("::").last.downcase
53
53
  end
54
-
54
+
55
55
  ##
56
56
  # Gets the model nodes hash
57
57
  def nodes
@@ -63,7 +63,7 @@ module C3sModel
63
63
  end
64
64
  nodes.keys
65
65
  end
66
-
66
+
67
67
  ##
68
68
  # Gets the model xml to include in a packet.
69
69
  # options:: [Hash] options
@@ -78,20 +78,20 @@ module C3sModel
78
78
  end
79
79
  xml
80
80
  end
81
-
81
+
82
82
  ##
83
83
  # Returns the first element for the model xml
84
84
  def first_element(options={})
85
85
  return options[:parent] if options[:parent]
86
-
86
+
87
87
  name = self._class_name
88
88
  name = name.pluralize if options[:plural]
89
89
  REXML::Element.new(name)
90
90
  end
91
-
91
+
92
92
  ##
93
93
  # Returns a default namespace based on class name
94
94
  def xmlns
95
95
  "http://c3s.av.it.pt/#{self._class_name}"
96
96
  end
97
- end
97
+ end
@@ -100,6 +100,7 @@ module C3s
100
100
  # node:: [String] the node to plublish to
101
101
  # content:: [REXML::Element] content xml to publish into node
102
102
  def publish(c3snode, content)
103
+ add_publish_date(content) if !has_publish_date(content)
103
104
  item = Jabber::PubSub::Item.new
104
105
  item.add(content)
105
106
  @pubsub.publish_item_to(c3snode.to_s, item)
@@ -120,5 +121,22 @@ module C3s
120
121
  rescue Jabber::ServerError => e
121
122
  return false if e.to_s.include?("item-not-found")
122
123
  end
124
+
125
+ private
126
+ ##
127
+ # Adds a <published> tag with the current time in RFC 822 format.
128
+ # xml:: [REXML::Element] content xml
129
+ def add_publish_date(xml)
130
+ root = xml.root
131
+ pub = REXML::Element.new("published").add_text(Time.now.rfc822)
132
+ root.add_element(pub)
133
+ end
134
+
135
+ ##
136
+ # Checks if the xml data has a <published> tag
137
+ # xml:: [REXML::Element] content xml
138
+ def has_publish_date(xml)
139
+ return xml.first_element("published")
140
+ end
123
141
  end
124
142
  end
data/lib/version.rb ADDED
@@ -0,0 +1,20 @@
1
+ module C3s
2
+ module VERSION
3
+ MAJOR = 0
4
+ MINOR = 4
5
+ TINY = 10
6
+
7
+ VERSION = [MAJOR, MINOR, TINY].join('.')
8
+
9
+ class << self
10
+ def to_s
11
+ VERSION
12
+ end
13
+ end
14
+ end
15
+
16
+ NAME = "C3S"
17
+ GEM_NAME = NAME
18
+ description = "Library to make context entities on C3S project."
19
+ DESCRIPTION = "#{NAME} #{VERSION} - #{description}"
20
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: c3s
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
5
- prerelease: false
4
+ hash: 27
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 6
10
- version: 0.4.6
9
+ - 10
10
+ version: 0.4.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ricardo Otero
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-22 00:00:00 +00:00
18
+ date: 2011-03-09 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
- description: C3s library gem.
22
+ description: C3S 0.4.10 - Library to make context entities on C3S project.
23
23
  email: oterosantos@gmail.com
24
24
  executables: []
25
25
 
@@ -39,9 +39,11 @@ extra_rdoc_files:
39
39
  - lib/pubsub/publisher.rb
40
40
  - lib/pubsub/subscriber.rb
41
41
  - lib/republisher.rb
42
+ - lib/version.rb
42
43
  files:
43
44
  - README.rdoc
44
45
  - Rakefile
46
+ - c3s
45
47
  - c3s.gemspec
46
48
  - lib/c3s.rb
47
49
  - lib/c3s_logger.rb
@@ -55,6 +57,7 @@ files:
55
57
  - lib/pubsub/publisher.rb
56
58
  - lib/pubsub/subscriber.rb
57
59
  - lib/republisher.rb
60
+ - lib/version.rb
58
61
  - Manifest
59
62
  has_rdoc: true
60
63
  homepage: http://github.com/rikas/c3s
@@ -92,9 +95,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
95
  requirements: []
93
96
 
94
97
  rubyforge_project: c3s
95
- rubygems_version: 1.3.7
98
+ rubygems_version: 1.4.1
96
99
  signing_key:
97
100
  specification_version: 3
98
- summary: C3s library gem.
101
+ summary: C3S 0.4.10 - Library to make context entities on C3S project.
99
102
  test_files: []
100
103