c3s 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +0 -1
- data/Rakefile +1 -1
- data/c3s.gemspec +2 -2
- data/lib/model.rb +54 -56
- metadata +2 -2
data/Manifest
CHANGED
data/Rakefile
CHANGED
data/c3s.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{c3s}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.4"
|
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"]
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.description = %q{C3s library gem.}
|
11
11
|
s.email = %q{oterosantos@gmail.com}
|
12
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/nodetracker.rb", "lib/publisher.rb"]
|
13
|
-
s.files = ["Manifest", "README.rdoc", "Rakefile", "
|
13
|
+
s.files = ["Manifest", "README.rdoc", "Rakefile", "lib/c3s.rb", "lib/c3s_logger.rb", "lib/component.rb", "lib/component_connection.rb", "lib/configreader.rb", "lib/databaseadapter.rb", "lib/model.rb", "lib/nodetracker.rb", "lib/publisher.rb", "c3s.gemspec"]
|
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"]
|
data/lib/model.rb
CHANGED
@@ -1,65 +1,63 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
nodes.delete(key)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
nodes.keys
|
32
|
-
end
|
33
|
-
|
34
|
-
##
|
35
|
-
# Gets the model xml to include in a packet.
|
36
|
-
# options:: [Hash] options
|
37
|
-
def to_xml(options={})
|
38
|
-
xml = first_element(options)
|
39
|
-
self.attributes.each do |key, val|
|
40
|
-
if !IGNORE_ATTR.include?(key) && !key.match(/.+_id/)
|
41
|
-
xml.add REXML::Element.new(key).add_text(value.to_s)
|
42
|
-
end
|
3
|
+
module C3sModel
|
4
|
+
##
|
5
|
+
# Attributes ignored and not included on model xml by default
|
6
|
+
IGNORE_ATTR = ["created_at", "updated_at", "id", "jid"]
|
7
|
+
|
8
|
+
##
|
9
|
+
# Updates multiple attributes at once
|
10
|
+
# attributes:: [Hash] the attributes hash
|
11
|
+
def update_attributes(attributes={})
|
12
|
+
self.send(:attributes=, attributes, false)
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# Returns the class name for this model without module name
|
17
|
+
def _class_name
|
18
|
+
@class_name ||= self.class.name.split("::").last.downcase
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# Gets the model nodes hash
|
23
|
+
def nodes
|
24
|
+
nodes = self.attributes
|
25
|
+
nodes.each do |key, val|
|
26
|
+
if IGNORE_ATTR.include?(key) or key.match(/.+_id/)
|
27
|
+
nodes.delete(key)
|
43
28
|
end
|
44
|
-
xml
|
45
29
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
30
|
+
nodes.keys
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Gets the model xml to include in a packet.
|
35
|
+
# options:: [Hash] options
|
36
|
+
def to_xml(options={})
|
37
|
+
xml = first_element(options)
|
38
|
+
self.attributes.each do |key, val|
|
39
|
+
if !IGNORE_ATTR.include?(key) && !key.match(/.+_id/)
|
40
|
+
xml.add REXML::Element.new(key).add_text(value.to_s)
|
56
41
|
end
|
57
42
|
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
43
|
+
xml
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# Returns the first element for the model xml
|
48
|
+
def first_element(options={})
|
49
|
+
if options[:parent]
|
50
|
+
first = options[:parent]
|
51
|
+
else
|
52
|
+
name = self._class_name
|
53
|
+
name = name.pluralize if options[:plural]
|
54
|
+
first = REXML::Element.new(name)
|
63
55
|
end
|
64
56
|
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# Returns a default namespace based on class name
|
60
|
+
def xmlns
|
61
|
+
"http://c3s.hng.av.it.pt/#{self._class_name}"
|
62
|
+
end
|
65
63
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: c3s
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Otero
|
@@ -34,7 +34,6 @@ files:
|
|
34
34
|
- Manifest
|
35
35
|
- README.rdoc
|
36
36
|
- Rakefile
|
37
|
-
- c3s.gemspec
|
38
37
|
- lib/c3s.rb
|
39
38
|
- lib/c3s_logger.rb
|
40
39
|
- lib/component.rb
|
@@ -44,6 +43,7 @@ files:
|
|
44
43
|
- lib/model.rb
|
45
44
|
- lib/nodetracker.rb
|
46
45
|
- lib/publisher.rb
|
46
|
+
- c3s.gemspec
|
47
47
|
has_rdoc: true
|
48
48
|
homepage: http://github.com/rikas/c3s
|
49
49
|
licenses: []
|