c3s 0.2.3 → 0.2.4

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.
Files changed (5) hide show
  1. data/Manifest +0 -1
  2. data/Rakefile +1 -1
  3. data/c3s.gemspec +2 -2
  4. data/lib/model.rb +54 -56
  5. metadata +2 -2
data/Manifest CHANGED
@@ -1,7 +1,6 @@
1
1
  Manifest
2
2
  README.rdoc
3
3
  Rakefile
4
- c3s.gemspec
5
4
  lib/c3s.rb
6
5
  lib/c3s_logger.rb
7
6
  lib/component.rb
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('c3s', '0.2.3') do |p|
5
+ Echoe.new('c3s', '0.2.4') do |p|
6
6
  p.description = "C3s library gem."
7
7
  p.url = "http://github.com/rikas/c3s"
8
8
  p.author = "Ricardo Otero"
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.3"
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", "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/nodetracker.rb", "lib/publisher.rb"]
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 C3s
4
- class Model < ActiveRecord::Base
5
- ##
6
- # Attributes ignored and not included on model xml by default
7
- IGNORE_ATTR = ["created_at", "updated_at", "id", "jid"]
8
-
9
- ##
10
- # Updates multiple attributes at once
11
- # attributes:: [Hash] the attributes hash
12
- def update_attributes(attributes={})
13
- self.send(:attributes=, attributes, false)
14
- end
15
-
16
- ##
17
- # Returns the class name for this model without module name
18
- def _class_name
19
- @class_name ||= self.class.name.split("::").last.downcase
20
- end
21
-
22
- ##
23
- # Gets the model nodes hash
24
- def self.nodes
25
- nodes = self.attributes
26
- nodes.each do |key, val|
27
- if IGNORE_ATTR.include?(key) or key.match(/.+_id/)
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
- # Returns the first element for the model xml
49
- def first_element(options={})
50
- if options[:parent]
51
- first = options[:parent]
52
- else
53
- name = self._class_name
54
- name = name.pluralize if options[:plural]
55
- first = REXML::Element.new(name)
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
- # Returns a default namespace based on class name
61
- def xmlns
62
- "http://c3s.hng.av.it.pt/#{self._class_name}"
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.3
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: []