opener-core 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43ff154454c7d19bb646f3293b1d0a19e4a56cff
4
- data.tar.gz: ef99757416af4cefb350959f4cab33b18a4a693e
3
+ metadata.gz: fb32f59ce0335afa43bacee5a96fb97ca475d7d9
4
+ data.tar.gz: ed38573de519ec4ec5b2093be5092ad830270d06
5
5
  SHA512:
6
- metadata.gz: 38e066cc9ab2bcd84c01d3ebb87c81bfe88fac5e0b4e59f0ae7e555c5c40cb74be575474366b1abf86951d545b7829dad769fbc4e761521873acd071742efcc5
7
- data.tar.gz: 82162da29bf7dab18e5df01b2a503f0d5b16d4260133060fff99a7a518ae873de2fdfe643868dda4683c45fb2c985a0724ba39beb5fdf4f03c5585f3080fb192
6
+ metadata.gz: bc40f6969b68fb51f8b01a997aa221951c6dfce0c41acc53c9be19c4d04234131bc0926cfc0e7a916b7a305b8e68c7f8f07759ebc60adf434c191cc94a0199a4
7
+ data.tar.gz: efbbd5b7f3059688f4086a21aee00198a96dd175b4694d26199bec41d9fa566d8d25b4b71cdb3c9beb6804b18650beed4b96f9c23e2aa69f1afe559cf8ac932e
@@ -0,0 +1,89 @@
1
+ require 'nokogiri'
2
+
3
+ module Opener
4
+ module Core
5
+ ##
6
+ # Add Error Layer to KAF file instead of throwing an error.
7
+ #
8
+ class ErrorLayer
9
+ attr_accessor :input, :document, :error, :klass
10
+
11
+ def initialize(input, error, klass)
12
+ @input = input.to_s
13
+ # Make sure there is always a document, even if it is empty.
14
+ @document = Nokogiri::XML(input) rescue Nokogiri::XML(nil)
15
+ @error = error
16
+ @klass = klass
17
+ end
18
+
19
+ def add
20
+ if is_xml?
21
+ unless has_errors_layer?
22
+ add_errors_layer
23
+ end
24
+ else
25
+ add_root
26
+ add_text
27
+ add_errors_layer
28
+ end
29
+ add_error
30
+
31
+ xml = !!document.encoding ? document.to_xml : document.to_xml(:encoding => "UTF-8")
32
+
33
+ return xml
34
+ end
35
+
36
+ ##
37
+ # Check if the document is a valid XML file.
38
+ #
39
+ def is_xml?
40
+ !!document.root
41
+ end
42
+
43
+ ##
44
+ # Add root element to the XML file.
45
+ #
46
+ def add_root
47
+ root = Nokogiri::XML::Node.new "KAF", document
48
+ document.add_child(root)
49
+ end
50
+
51
+ ##
52
+ # Check if the document already has an errors layer.
53
+ #
54
+ def has_errors_layer?
55
+ !!document.at('errors')
56
+ end
57
+
58
+ ##
59
+ # Add errors element to the XML file.
60
+ #
61
+ def add_errors_layer
62
+ node = Nokogiri::XML::Node.new "errors", document
63
+ document.root.add_child(node)
64
+ end
65
+
66
+ ##
67
+ # Add the text file incase it is not a valid XML document. More
68
+ # info for debugging.
69
+ #
70
+ def add_text
71
+ node = Nokogiri::XML::Node.new "raw", document
72
+ node.inner_html = input
73
+ document.root.add_child(node)
74
+ end
75
+
76
+ ##
77
+ # Add the actual error to the errors layer.
78
+ #
79
+ def add_error
80
+ node = document.at('errors')
81
+ error_node = Nokogiri::XML::Node.new "error", node
82
+ error_node['class'] = klass.to_s
83
+ error_node['version'] = klass::VERSION
84
+ error_node.inner_html = error
85
+ node.add_child(error_node)
86
+ end
87
+ end # ErrorLayer
88
+ end # Core
89
+ end # Opener
@@ -1,5 +1,5 @@
1
1
  module Opener
2
2
  module Core
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
  end
5
5
  end
data/lib/opener/core.rb CHANGED
@@ -10,3 +10,4 @@ require_relative 'core/opt_parser'
10
10
  require_relative 'core/resource_switcher'
11
11
  require_relative 'core/memory_usage'
12
12
  require_relative 'core/benchmark'
13
+ require_relative 'core/error_layer'
metadata CHANGED
@@ -1,73 +1,73 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - development@olery.com
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-17 00:00:00.000000000 Z
11
+ date: 2014-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
15
20
  requirement: !ruby/object:Gem::Requirement
16
21
  requirements:
17
- - - ">="
22
+ - - '>='
18
23
  - !ruby/object:Gem::Version
19
24
  version: '0'
20
- type: :runtime
21
25
  prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
22
29
  version_requirements: !ruby/object:Gem::Requirement
23
30
  requirements:
24
- - - ">="
31
+ - - '>='
25
32
  - !ruby/object:Gem::Version
26
33
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
34
  requirement: !ruby/object:Gem::Requirement
30
35
  requirements:
31
- - - ">="
36
+ - - '>='
32
37
  - !ruby/object:Gem::Version
33
38
  version: '0'
34
- type: :development
35
39
  prerelease: false
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
36
43
  version_requirements: !ruby/object:Gem::Requirement
37
44
  requirements:
38
- - - ">="
45
+ - - '>='
39
46
  - !ruby/object:Gem::Version
40
47
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
48
  requirement: !ruby/object:Gem::Requirement
44
49
  requirements:
45
- - - ">="
50
+ - - '>='
46
51
  - !ruby/object:Gem::Version
47
52
  version: '0'
48
- type: :development
49
53
  prerelease: false
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
50
57
  version_requirements: !ruby/object:Gem::Requirement
51
58
  requirements:
52
- - - ">="
59
+ - - '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
62
  requirement: !ruby/object:Gem::Requirement
58
63
  requirements:
59
- - - ">="
64
+ - - '>='
60
65
  - !ruby/object:Gem::Version
61
66
  version: '0'
62
- type: :development
63
67
  prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
68
+ type: :development
69
69
  description: Gem that contains some low level generic functions for all OpeNER components.
70
- email:
70
+ email:
71
71
  executables: []
72
72
  extensions: []
73
73
  extra_rdoc_files: []
@@ -76,6 +76,7 @@ files:
76
76
  - lib/opener/core.rb
77
77
  - lib/opener/core/argv_splitter.rb
78
78
  - lib/opener/core/benchmark.rb
79
+ - lib/opener/core/error_layer.rb
79
80
  - lib/opener/core/memory_usage.rb
80
81
  - lib/opener/core/opt_parser.rb
81
82
  - lib/opener/core/resource_switcher.rb
@@ -85,25 +86,24 @@ homepage: http://opener-project.github.com
85
86
  licenses:
86
87
  - Apachev2
87
88
  metadata: {}
88
- post_install_message:
89
+ post_install_message:
89
90
  rdoc_options: []
90
91
  require_paths:
91
92
  - lib
92
93
  required_ruby_version: !ruby/object:Gem::Requirement
93
94
  requirements:
94
- - - ">="
95
+ - - '>='
95
96
  - !ruby/object:Gem::Version
96
97
  version: '0'
97
98
  required_rubygems_version: !ruby/object:Gem::Requirement
98
99
  requirements:
99
- - - ">="
100
+ - - '>='
100
101
  - !ruby/object:Gem::Version
101
102
  version: '0'
102
103
  requirements: []
103
- rubyforge_project:
104
+ rubyforge_project:
104
105
  rubygems_version: 2.2.2
105
- signing_key:
106
+ signing_key:
106
107
  specification_version: 4
107
108
  summary: Gem that contains some low level generic functions for all OpeNER components.
108
109
  test_files: []
109
- has_rdoc: