fog-xml 0.1.0 → 0.1.4

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
- SHA1:
3
- metadata.gz: ce8f9b8d09cf440bc8510dbf67d2cc23d4fcec4b
4
- data.tar.gz: 529565cb7aa30250af6877f4fdaec10d6e9f043e
2
+ SHA256:
3
+ metadata.gz: f20443f996f68c6657e65d1997355153ff80094d68fbe227a52e43298f6b216a
4
+ data.tar.gz: 0f1234f7218d87805b644e4c8797b0f11209217c048e61669d838057c0b64b9e
5
5
  SHA512:
6
- metadata.gz: 4343f03be19f667da0a02a475976974f4ce0670908c45beb95dfd69a15a5df0dc12999e17e05e0ac1ab0552dd68c53a4776efb27921b877e4aabb696b6685660
7
- data.tar.gz: 963c88b5c7326f967f9df6b8280ef8ad9d5e89e46b0ffd269a23a2518aa563c79e2b512a99b8e8cc3532721915ec33a65733e4d3bd590aeef8b0d2a9fb175909
6
+ metadata.gz: c3965c992d6845bd68a637c825fd3133fb80eb23b7956bbd4b81ecb56f24343f62815c0ca13ce5b4168e40e102a636df1bd80374e32e413e950694e423e57b61
7
+ data.tar.gz: 5f6e0f9b03ffeb84212d085148d5b776c1fe7613d61f44dc99129f4707b74c3eb46dc4baaf5476f35d4d7cd941a56b0425f103d119a21750b9ec6765cf8c85a5
@@ -0,0 +1,10 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "bundler"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "daily"
7
+ - package-ecosystem: "github-actions"
8
+ directory: "/"
9
+ schedule:
10
+ interval: "daily"
@@ -0,0 +1,34 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.5', '2.6', '2.7', '3.0', 'head']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2.3.4
26
+ - name: Set up Ruby
27
+ uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby-version }}
30
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
31
+ - name: Install dependencies
32
+ run: bundle install
33
+ - name: Run tests
34
+ run: bundle exec rake
@@ -0,0 +1,23 @@
1
+ name: Mark stale issues and pull requests
2
+
3
+ on:
4
+ schedule:
5
+ - cron: "30 1 * * *"
6
+
7
+ jobs:
8
+ stale:
9
+
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/stale@v4
14
+ with:
15
+ repo-token: ${{ secrets.GITHUB_TOKEN }}
16
+ days-before-stale: 60
17
+ days-before-close: 7
18
+ exempt-issue-labels: 'pinned,security'
19
+ exempt-pr-labels: 'pinned,security'
20
+ stale-issue-message: 'This issue has been marked inactive and will be closed if no further activity occurs.'
21
+ stale-pr-message: 'This pr has been marked inactive and will be closed if no further activity occurs.'
22
+ stale-issue-label: 'no-issue-activity'
23
+ stale-pr-label: 'no-pr-activity'
data/CONTRIBUTORS.md CHANGED
@@ -1,4 +1,5 @@
1
1
  * Michael Hale <mike@hales.ws>
2
2
  * Paul Thornthwaite <tokengeek@gmail.com>
3
3
  * Paulo Henrique Lopes Ribeiro <plribeiro3000@gmail.com>
4
- * Wesley Beary <geemus@gmail.com>
4
+ * Wesley Beary <geemus@gmail.com>
5
+ * Tomer Brisker <tbrisker@gmail.com>
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Fog::Xml
2
2
 
3
- TODO: Write a gem description
3
+ Shared XML related functionality for fog
4
+
5
+ ![Gem Version](https://badge.fury.io/rb/fog-xml.svg) [![Build Status](https://travis-ci.org/fog/fog-xml.svg?branch=master)](https://travis-ci.org/fog/fog-xml) [![Dependency Status](https://gemnasium.com/fog/fog-xml.svg)](https://gemnasium.com/fog/fog-xml) [![Coverage Status](https://img.shields.io/coveralls/fog/fog-xml.svg)](https://coveralls.io/r/fog/fog-xml?branch=master) [![Code Climate](https://codeclimate.com/github/fog/fog-xml/badges/gpa.svg)](https://codeclimate.com/github/fog/fog-xml)
4
6
 
5
7
  ## Installation
6
8
 
@@ -22,7 +24,7 @@ TODO: Write usage instructions here
22
24
 
23
25
  ## Contributing
24
26
 
25
- 1. Fork it ( https://github.com/zertico/fog-xml/fork )
27
+ 1. Fork it ( https://github.com/fog/fog-xml/fork )
26
28
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
29
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
30
  4. Push to the branch (`git push origin my-new-feature`)
data/fog-xml.gemspec CHANGED
@@ -14,17 +14,21 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/fog/fog-xml"
15
15
  spec.license = "MIT"
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0")
17
+ files = `git ls-files -z`.split("\x0")
18
+ files.delete(".hound.yml")
19
+ spec.files = files
20
+
18
21
  spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
19
22
  spec.test_files = spec.files.grep(/^(test|spec|features)\//)
20
23
  spec.require_paths = %w(lib)
21
24
 
25
+ spec.required_ruby_version = '>= 2.0.0'
26
+
22
27
  spec.add_dependency "fog-core"
23
- spec.add_dependency "nokogiri", "~> 1.5", ">= 1.5.11"
28
+ spec.add_dependency "nokogiri", ">= 1.5.11", "< 2.0.0" #pinned for 2.0 support
24
29
  spec.add_development_dependency "rake"
25
30
  spec.add_development_dependency "minitest"
26
31
  spec.add_development_dependency "turn"
27
32
  spec.add_development_dependency "pry"
28
- spec.add_development_dependency "rubocop"
29
- spec.add_development_dependency "coveralls" if RUBY_VERSION.to_f >= 1.9
33
+ spec.add_development_dependency "coveralls"
30
34
  end
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'activesupport', '>= 3.0', '< 4'
4
+ gem 'mime-types', '< 2.0'
5
+ gem 'fog-core'
6
+
7
+ gemspec :path => '../'
@@ -0,0 +1,48 @@
1
+ require "nokogiri"
2
+
3
+ module Fog
4
+ module Parsers
5
+ class Base < Nokogiri::XML::SAX::Document
6
+ attr_reader :response
7
+
8
+ def initialize
9
+ reset
10
+ end
11
+
12
+ def attr_value(name, attrs)
13
+ (entry = attrs.find {|a| a.localname == name }) && entry.value
14
+ end
15
+
16
+ def reset
17
+ @response = {}
18
+ end
19
+
20
+ def characters(string)
21
+ @value ||= ''
22
+ @value << string
23
+ end
24
+
25
+ # ###############################################################################
26
+ # This is a workaround. Original implementation from Nokogiri is overwritten with
27
+ # one that does not join namespace prefix with local name.
28
+ def start_element_namespace name, attrs = [], prefix = nil, uri = nil, ns = []
29
+ start_element name, attrs
30
+ end
31
+
32
+ def end_element_namespace name, prefix = nil, uri = nil
33
+ end_element name
34
+ end
35
+
36
+ # ###############################################################################
37
+
38
+ def start_element(name, attrs = [])
39
+ @value = nil
40
+ end
41
+
42
+ def value
43
+ @value && @value.dup
44
+ end
45
+ end
46
+ end
47
+ end
48
+
@@ -0,0 +1,26 @@
1
+ module Fog
2
+ module XML
3
+ class Response
4
+ def initialize(parser)
5
+ @parser = parser
6
+ @data_stream = Nokogiri::XML::SAX::PushParser.new(parser)
7
+ @response_string = ""
8
+ end
9
+
10
+ def call(chunk, _remaining, _total)
11
+ @response_string << chunk if ENV["DEBUG_RESPONSE"]
12
+ @data_stream << chunk
13
+ end
14
+
15
+ def rewind
16
+ @parser.reset
17
+ @response_string = ""
18
+ end
19
+
20
+ def finish
21
+ Fog::Logger.debug "\n#{@response_string}" if ENV["DEBUG_RESPONSE"]
22
+ @data_stream.finish
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,3 @@
1
- require "fog/core/connection"
2
-
3
1
  module Fog
4
2
  module XML
5
3
  class SAXParserConnection < ::Fog::Core::Connection
@@ -25,20 +23,13 @@ module Fog
25
23
  def request(parser, params)
26
24
  reset unless @persistent
27
25
 
28
- # Prepare the SAX parser
29
- data_stream = Nokogiri::XML::SAX::PushParser.new(parser)
30
- response_string = ""
31
- params[:response_block] = lambda do |chunk, _remaining, _total|
32
- response_string << chunk if ENV["DEBUG_RESPONSE"]
33
- data_stream << chunk
34
- end
26
+ params[:response_block] = ::Fog::XML::Response.new(parser)
35
27
 
36
28
  # Make request which read chunks into parser
37
29
  response = @excon.request(params)
38
- Fog::Logger.debug "\n#{response_string}" if ENV["DEBUG_RESPONSE"]
39
30
 
40
31
  # Cease parsing and override response.body with parsed data
41
- data_stream.finish
32
+ params[:response_block].finish
42
33
  response.body = parser.response
43
34
  response
44
35
  end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Xml
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
data/lib/fog/xml.rb CHANGED
@@ -1,11 +1,17 @@
1
- require "fog/xml/version"
1
+ require "fog/core"
2
2
  require "nokogiri"
3
+ require File.expand_path("../xml/version", __FILE__)
3
4
 
4
5
  module Fog
5
- autoload :ToHashDocument, "fog/to_hash_document"
6
+ autoload :ToHashDocument, File.expand_path("../to_hash_document", __FILE__)
6
7
 
7
8
  module XML
8
- autoload :SAXParserConnection, "fog/xml/sax_parser_connection"
9
- autoload :Connection, "fog/xml/connection"
9
+ autoload :SAXParserConnection, File.expand_path("../xml/sax_parser_connection", __FILE__)
10
+ autoload :Connection, File.expand_path("../xml/connection", __FILE__)
11
+ autoload :Response, File.expand_path("../xml/response", __FILE__)
12
+ end
13
+
14
+ module Parsers
15
+ autoload :Base, File.expand_path("../parsers/base", __FILE__)
10
16
  end
11
17
  end
@@ -0,0 +1,73 @@
1
+ require "minitest_helper"
2
+
3
+ describe Fog::Parsers::Base do
4
+
5
+ def parse(input, parser_class)
6
+ document = parser_class.new
7
+ parser = Nokogiri::XML::SAX::Parser.new(document)
8
+ parser.parse input
9
+ document.response
10
+ end
11
+
12
+ describe 'value' do
13
+ class ValueTest < Fog::Parsers::Base
14
+
15
+ def start_element(name, attrs)
16
+ @stack.push({})
17
+ super
18
+ end
19
+
20
+ def reset
21
+ super
22
+ @stack = [@response]
23
+ end
24
+
25
+ def end_element name
26
+ top = @stack.pop
27
+ if top.empty?
28
+ @stack.last[name] = value
29
+ else
30
+ @stack.last[name] = top if @stack.any?
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ it 'extracts the characters for the current element' do
37
+ doc = <<-XML
38
+ <Test>
39
+ <Foo>FooValue</Foo>
40
+ <Bar>BarValue</Bar>
41
+ </Test>
42
+ XML
43
+ assert_equal({'Test'=> {'Foo' => 'FooValue', 'Bar' => 'BarValue'}}, parse(doc, ValueTest))
44
+ end
45
+ end
46
+
47
+ describe 'attr_value' do
48
+ class AttrParser < Fog::Parsers::Base
49
+ def start_element(name, attrs=[])
50
+ super
51
+ @response[name] = {'foo' => attr_value('foo', attrs)}
52
+ end
53
+ end
54
+
55
+ describe 'the attribute exists' do
56
+ it 'returns the value' do
57
+ doc = <<-XML
58
+ <Test foo="bar" />
59
+ XML
60
+ assert_equal({'Test'=> {'foo' => 'bar'}}, parse(doc, AttrParser))
61
+ end
62
+ end
63
+
64
+ describe 'the attribute does not exist' do
65
+ it 'returns nil' do
66
+ doc = <<-XML
67
+ <Test notfoo="bar" />
68
+ XML
69
+ assert_equal({'Test'=> {'foo' => nil}}, parse(doc, AttrParser))
70
+ end
71
+ end
72
+ end
73
+ end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wesley Beary (geemus)
8
8
  - Paul Thornthwaite (tokengeek)
9
9
  - The fog team
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-09-26 00:00:00.000000000 Z
13
+ date: 2021-10-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fog-core
@@ -30,22 +30,22 @@ dependencies:
30
30
  name: nokogiri
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - "~>"
34
- - !ruby/object:Gem::Version
35
- version: '1.5'
36
33
  - - ">="
37
34
  - !ruby/object:Gem::Version
38
35
  version: 1.5.11
36
+ - - "<"
37
+ - !ruby/object:Gem::Version
38
+ version: 2.0.0
39
39
  type: :runtime
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
42
42
  requirements:
43
- - - "~>"
44
- - !ruby/object:Gem::Version
45
- version: '1.5'
46
43
  - - ">="
47
44
  - !ruby/object:Gem::Version
48
45
  version: 1.5.11
46
+ - - "<"
47
+ - !ruby/object:Gem::Version
48
+ version: 2.0.0
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rake
51
51
  requirement: !ruby/object:Gem::Requirement
@@ -102,20 +102,6 @@ dependencies:
102
102
  - - ">="
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
- - !ruby/object:Gem::Dependency
106
- name: rubocop
107
- requirement: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- version: '0'
112
- type: :development
113
- prerelease: false
114
- version_requirements: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- version: '0'
119
105
  - !ruby/object:Gem::Dependency
120
106
  name: coveralls
121
107
  requirement: !ruby/object:Gem::Requirement
@@ -140,11 +126,12 @@ executables: []
140
126
  extensions: []
141
127
  extra_rdoc_files: []
142
128
  files:
129
+ - ".github/dependabot.yml"
130
+ - ".github/workflows/ruby.yml"
131
+ - ".github/workflows/stale.yml"
143
132
  - ".gitignore"
144
133
  - ".rubocop.yml"
145
134
  - ".ruby-gemset"
146
- - ".ruby-version"
147
- - ".travis.yml"
148
135
  - CONTRIBUTING.md
149
136
  - CONTRIBUTORS.md
150
137
  - Gemfile
@@ -152,20 +139,22 @@ files:
152
139
  - README.md
153
140
  - Rakefile
154
141
  - fog-xml.gemspec
155
- - gemfiles/Gemfile.1.8.7
156
- - gemfiles/Gemfile.1.9.2+
142
+ - gemfiles/Gemfile.1.9.3+
143
+ - lib/fog/parsers/base.rb
157
144
  - lib/fog/to_hash_document.rb
158
145
  - lib/fog/xml.rb
159
146
  - lib/fog/xml/connection.rb
147
+ - lib/fog/xml/response.rb
160
148
  - lib/fog/xml/sax_parser_connection.rb
161
149
  - lib/fog/xml/version.rb
150
+ - spec/fog/parsers/base_spec.rb
162
151
  - spec/fog/xml/connection_spec.rb
163
152
  - spec/minitest_helper.rb
164
153
  homepage: https://github.com/fog/fog-xml
165
154
  licenses:
166
155
  - MIT
167
156
  metadata: {}
168
- post_install_message:
157
+ post_install_message:
169
158
  rdoc_options: []
170
159
  require_paths:
171
160
  - lib
@@ -173,18 +162,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
162
  requirements:
174
163
  - - ">="
175
164
  - !ruby/object:Gem::Version
176
- version: '0'
165
+ version: 2.0.0
177
166
  required_rubygems_version: !ruby/object:Gem::Requirement
178
167
  requirements:
179
168
  - - ">="
180
169
  - !ruby/object:Gem::Version
181
170
  version: '0'
182
171
  requirements: []
183
- rubyforge_project:
184
- rubygems_version: 2.2.2
185
- signing_key:
172
+ rubygems_version: 3.2.15
173
+ signing_key:
186
174
  specification_version: 4
187
175
  summary: XML parsing for fog providers
188
176
  test_files:
177
+ - spec/fog/parsers/base_spec.rb
189
178
  - spec/fog/xml/connection_spec.rb
190
179
  - spec/minitest_helper.rb
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.1.2
data/.travis.yml DELETED
@@ -1,21 +0,0 @@
1
- matrix:
2
- include:
3
- - rvm: 1.8.7
4
- gemfile: gemfiles/Gemfile.1.8.7
5
- - rvm: 1.9.2
6
- gemfile: gemfiles/Gemfile.1.9.2+
7
- env: COVERAGE=true
8
- - rvm: 1.9.3
9
- gemfile: gemfiles/Gemfile.1.9.2+
10
- env: COVERAGE=true
11
- - rvm: 2.0.0
12
- gemfile: gemfiles/Gemfile.1.9.2+
13
- env: COVERAGE=true
14
- - rvm: 2.1.1
15
- gemfile: gemfiles/Gemfile.1.9.2+
16
- env: COVERAGE=true
17
- - rvm: ree
18
- gemfile: gemfiles/Gemfile.1.8.7
19
- - rvm: jruby
20
- gemfile: gemfiles/Gemfile.1.9.2+
21
- env: COVERAGE=true
@@ -1,8 +0,0 @@
1
- source :rubygems
2
-
3
- gem 'mime-types', '< 2.0'
4
- gem 'nokogiri', '< 1.6'
5
- gem 'rest-client', '~> 1.6.8'
6
- gem 'fog-core', :github => 'fog/fog-core'
7
-
8
- gemspec :path => '../'
@@ -1,7 +0,0 @@
1
- source :rubygems
2
-
3
- gem 'activesupport', '>= 3.0', '< 4'
4
- gem 'mime-types', '< 2.0'
5
- gem 'fog-core', :github => 'fog/fog-core'
6
-
7
- gemspec :path => '../'