nom-xml 0.5.4 → 1.2.0

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: bb52919534624c32a6a015dec49c1b7070d0c933
4
- data.tar.gz: b64cc4bba00bee3b5afef3f67ca877fab87a9b44
2
+ SHA256:
3
+ metadata.gz: 2b2ab72999bcce7d9fc1173c01393e03d8e2388428d90943e2fe1831f8b52563
4
+ data.tar.gz: 6c1c4a29b276fc07afe6bfd241f4a2a29105e49a9e20c39801f15577dc512889
5
5
  SHA512:
6
- metadata.gz: 76735f5e2789f473ad4354778775a2cf3292b83c4f25caf1d5fab17e984cb7ab478acd78c775b32dcb9106dc9a8a708640de9cf6f909cd6f70bf61035a89934b
7
- data.tar.gz: c5fe6162f42f5e05ee41d8069ce1bcf9ba42912dc4467b55a7820604244b4bfdb5d0ef2e8a495e4e7ac0db4f16fe724d30c0a4365a04cf789f63a5c6b3498013
6
+ metadata.gz: 91ac790f990da5482c3489d3e57d0c014e01f9684ad408e5202e792d8f581d0412df55b427435aa320250ef9398a2f774c81c1abfda151f0ba7a55c94d20e8a9
7
+ data.tar.gz: 0ecd92b30918cde11a15197ea58edc6ccbc2d479a7a2f7d010789eee303f55edfac4cff0525dfbe972349f72cc49e4d4d43fc82ccb16422b343ae2a3593cbcea
@@ -0,0 +1,24 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ tests:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby: [jruby-9.2.12.0, 2.4, 2.5, 2.6, 2.7, 3.0]
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby }}
21
+ - name: Install dependencies
22
+ run: bundle install
23
+ - name: Run tests
24
+ run: bundle exec rake
data/Gemfile CHANGED
@@ -2,8 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'simplecov', :platform => :ruby_19
6
- gem 'rcov', :platform => :ruby_18
7
- gem 'debugger', :platform => :mri_19
8
- gem "redcarpet", :platform => :ruby_19
9
- gem 'byebug'
5
+ gem 'simplecov'
6
+ gem 'byebug', platform: :mri
data/Rakefile CHANGED
@@ -10,25 +10,8 @@ rescue Bundler::BundlerError => e
10
10
  exit e.status_code
11
11
  end
12
12
 
13
- task :default => :ci
13
+ task default: :spec
14
14
 
15
15
  require 'rspec/core/rake_task'
16
16
  desc "Run specs"
17
- RSpec::Core::RakeTask.new do |t|
18
-
19
- if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.8/
20
- t.rcov = true
21
- t.rcov_opts = %w{--exclude spec\/*,gems\/*,ruby\/* --aggregate coverage.data}
22
- end
23
- end
24
-
25
- require 'yard'
26
- YARD::Rake::YardocTask.new do |t|
27
- t.options = ["--readme", "README.md"]
28
- end
29
-
30
- desc "Continuous Integration build"
31
- task :ci do
32
- Rake::Task['spec'].invoke
33
- # Rake::Task['yard'].invoke
34
- end
17
+ RSpec::Core::RakeTask.new(:spec)
@@ -31,7 +31,11 @@ module Nom::XML::Decorators::NodeSet
31
31
  def method_missing sym, *args, &block
32
32
  if self.all? { |node| node.respond_to? sym }
33
33
  result = self.collect { |node| node.send(sym, *args, &block) }.flatten
34
- self.class.new(self.document, result) rescue result
34
+ if result.empty? || result.any? { |x| x.is_a? Nokogiri::XML::Node }
35
+ self.class.new(self.document, result) rescue result
36
+ else
37
+ result
38
+ end
35
39
  else
36
40
  begin
37
41
  self.document.template_registry.send(sym, self, *args, &block)
@@ -1,19 +1,4 @@
1
1
  module Nom::XML::Decorators::Terminology
2
-
3
- def self.extended node
4
- node.add_terminology_method_overrides!
5
- end
6
-
7
- def add_terminology_method_overrides!
8
- self.term_accessors.each do |k, term|
9
- if self.respond_to_without_terms? k and not term.options[:override]
10
- raise "Trying to redefine method #{k} on #{self.to_s}"
11
- end
12
- end.select { |k, term| term.options[:override] }.each do |method, term|
13
- define_term_method(method, self.term_accessors[method.to_sym])
14
- end
15
- end
16
-
17
2
  def method_missing method, *args, &block
18
3
  if self.term_accessors[method.to_sym]
19
4
  define_term_method(method, self.term_accessors[method.to_sym])
@@ -97,9 +82,7 @@ module Nom::XML::Decorators::Terminology
97
82
  end
98
83
 
99
84
  def lookup_term term, *args
100
- options = args.extract_options!
101
-
102
- args += options.map { |key, value| %{#{key}="#{value.gsub(/"/, '\\\"') }"} }
85
+ args = extract_term_options(*args)
103
86
 
104
87
  xpath = term.local_xpath
105
88
 
@@ -114,4 +97,14 @@ module Nom::XML::Decorators::Terminology
114
97
 
115
98
  result.values_for_term(term)
116
99
  end
100
+
101
+ def extract_term_options(*args)
102
+ if args.last.is_a? Hash
103
+ h = args.pop
104
+
105
+ args + h.map { |key, value| %(#{key}="#{value.gsub(/"/, '\\\"')}") }
106
+ else
107
+ args
108
+ end
109
+ end
117
110
  end
@@ -1,5 +1,3 @@
1
- require 'active_support/core_ext/array'
2
-
3
1
  module Nom::XML
4
2
  module NokogiriExtension
5
3
 
@@ -24,7 +22,7 @@ module Nom::XML
24
22
  # Set the terminology accessors for this document
25
23
  def set_terminology options = {}, &block
26
24
  @terminology = Nom::XML::Terminology.new(self, options, &block)
27
-
25
+
28
26
  self
29
27
  end
30
28
 
data/lib/nom/xml/term.rb CHANGED
@@ -16,6 +16,10 @@ module Nom::XML
16
16
  # @attr [Hash] options
17
17
  # @yield
18
18
  def initialize parent, name, options = {}, *args, &block
19
+ if Nokogiri::XML::Node.instance_methods.include?(name.to_sym)
20
+ raise "Unable to redefine method #{name} on Nokogiri::XML::Node"
21
+ end
22
+
19
23
  @name = name
20
24
  @terms = {}
21
25
  @parent = parent
@@ -48,7 +52,7 @@ module Nom::XML
48
52
  # Get the relative xpath to this node from its immediate parent's term
49
53
  # @return [String]
50
54
  def local_xpath
51
- xpath = if xmlns.blank?
55
+ xpath = if xmlns.nil? || xmlns.empty?
52
56
  ""
53
57
  else
54
58
  xmlns + ":"
@@ -1,5 +1,5 @@
1
1
  module Nom
2
2
  module XML
3
- VERSION = '0.5.4'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
data/nom-xml.gemspec CHANGED
@@ -12,7 +12,6 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q{ A library to help you tame sprawling XML schemas. }
13
13
  s.description = %q{ NOM allows you to define a “terminology” to ease translation between XML and ruby objects }
14
14
 
15
- s.add_dependency 'activesupport', '>= 3.2.18' # could be rails/AS 3 or 4+, but we don't support old insecure versions
16
15
  s.add_dependency 'i18n'
17
16
  s.add_dependency 'nokogiri'
18
17
 
@@ -13,7 +13,7 @@ describe "Namespaces example" do
13
13
 
14
14
  t.author :path => '//mods:name' do |n|
15
15
  n.authorityURI :path => '@authorityURI', :accessor => lambda { |e| e.text }
16
- n.description :path => 'mods:description', :override => true
16
+ n.mods_description :path => 'mods:description'
17
17
  n.valueURI :path => '@valueURI'
18
18
  n.namePart :path => 'mods:namePart', :single => true, :index_as => [:type_1]
19
19
  end
@@ -39,10 +39,6 @@ describe "Namespaces example" do
39
39
  xml
40
40
  }
41
41
 
42
- it "should work with existing reserved method names when override is present" do
43
- expect(subject.author.first.description.text).to include('asdf')
44
- end
45
-
46
42
  it "should return nodesets by default" do
47
43
  expect(subject.personal_authors).to be_a_kind_of(Nokogiri::XML::NodeSet)
48
44
  end
@@ -32,23 +32,6 @@ describe "Nutrition" do
32
32
  xml
33
33
  }
34
34
 
35
- describe "#add_terminology_method_overrides!" do
36
-
37
- it "should warn you if you try to override already existing methods" do
38
- pending if defined? JRUBY_VERSION
39
- mock_term = {:text => double(:options => {})}
40
- allow(document.a.first).to receive(:term_accessors).and_return mock_term
41
- expect { document.a.first.add_terminology_method_overrides! }.to raise_error /Trying to redefine/
42
- end
43
-
44
- it "should let you override the warning" do
45
- pending if defined? JRUBY_VERSION
46
- mock_term = {:text => double(:options => { :override => true } )}
47
- allow(document.a.first).to receive(:term_accessors).and_return mock_term
48
- expect { document.a.first.add_terminology_method_overrides! }.to_not raise_error
49
- end
50
- end
51
-
52
35
  describe "#terms" do
53
36
 
54
37
  context "root element" do
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,9 @@
1
- if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.9/
2
- require 'simplecov'
3
- SimpleCov.start
4
- end
1
+ require 'simplecov'
2
+ SimpleCov.start
5
3
 
6
4
  require 'rspec'
7
5
  require 'nom'
8
6
  require 'equivalent-xml/rspec_matchers'
9
-
10
7
  RSpec.configure do |config|
11
8
 
12
9
  end
13
-
metadata CHANGED
@@ -1,30 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nom-xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  - Michael B. Klein
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-09 00:00:00.000000000 Z
12
+ date: 2022-01-10 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: activesupport
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: 3.2.18
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: 3.2.18
28
14
  - !ruby/object:Gem::Dependency
29
15
  name: i18n
30
16
  requirement: !ruby/object:Gem::Requirement
@@ -118,15 +104,13 @@ extra_rdoc_files:
118
104
  - LICENSE
119
105
  - README.md
120
106
  files:
107
+ - ".github/workflows/ruby.yml"
121
108
  - ".gitignore"
122
109
  - ".rspec"
123
- - ".travis.yml"
124
110
  - Gemfile
125
111
  - LICENSE
126
112
  - README.md
127
113
  - Rakefile
128
- - gemfiles/rails3.gemfile
129
- - gemfiles/rails4.gemfile
130
114
  - lib/nom.rb
131
115
  - lib/nom/xml.rb
132
116
  - lib/nom/xml/decorators.rb
@@ -156,7 +140,7 @@ files:
156
140
  homepage: http://github.com/cbeer/nom-xml
157
141
  licenses: []
158
142
  metadata: {}
159
- post_install_message:
143
+ post_install_message:
160
144
  rdoc_options: []
161
145
  require_paths:
162
146
  - lib
@@ -171,9 +155,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
155
  - !ruby/object:Gem::Version
172
156
  version: '0'
173
157
  requirements: []
174
- rubyforge_project:
175
- rubygems_version: 2.4.5.1
176
- signing_key:
158
+ rubygems_version: 3.2.32
159
+ signing_key:
177
160
  specification_version: 4
178
161
  summary: A library to help you tame sprawling XML schemas.
179
162
  test_files:
@@ -191,4 +174,3 @@ test_files:
191
174
  - spec/lib/terminology_spec.rb
192
175
  - spec/spec_helper.rb
193
176
  - spec/test_spec.rb
194
- has_rdoc:
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- notifications:
2
- email: false
3
-
4
- gemfile:
5
- - gemfiles/rails3.gemfile
6
- - gemfiles/rails4.gemfile
7
-
8
- rvm:
9
- - 1.9.3
10
- - jruby-19mode
11
- - rbx-19mode
12
- - 2.0.0
13
- - 2.1.2
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec :path=>"../"
4
-
5
- gem 'activesupport', '~> 3.2', '>= 3.2.18'
6
-
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec :path=>"../"
4
-
5
- gem 'activesupport', '~> 4.1'
6
-