agris 0.1.1 → 0.1.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: 20e4fbd4cf0eeba824e44803db53a7257616bc29
4
- data.tar.gz: 4ee76f64b8c6a5b7d6d3ac56d6a31ee2686eb2e5
3
+ metadata.gz: a4d090ac08f37e8b68e3c5573667111b9f42f1b7
4
+ data.tar.gz: 2bb7298c5c672b810b2c35c50c0be3dd205660dc
5
5
  SHA512:
6
- metadata.gz: 30f1ef8a65c1b59721d0e4ac265ad53adad2c095fdd63ce9a09872e437c0fa688364ccccd915dd06647b517ddfd9f15e5c4ee15782d36f35c150ca7edbae5ccd
7
- data.tar.gz: 7a4e1980e79f214ee8b317c1744b187ff84f5262701fb12175b184a9e265ece448d3c4d667e1c3b297a44472f578b0c706b2f14fea91dcfe18a5954ac2394069
6
+ metadata.gz: 21762b562cff9392c8976854e4b3c52dab34b00f2900ac764b93dddd16f38a585baba01e6f11c0b8466a84ec1e90bf4a83fc4d259ac59078ec34b77e0bdb2b4c
7
+ data.tar.gz: 2dce9ba1d5a2f50502c091da42a3372c8c4593b5165681c45d5aca1dec5a08ce91b826562ddac2c0a9d571857d3567fd87975333b4d4db9b5e0a89928d98826c
@@ -241,79 +241,3 @@ Lint/LiteralInCondition:
241
241
  Lint/LiteralInInterpolation:
242
242
  Description: Checks for literals used in interpolation.
243
243
  Enabled: false
244
-
245
- ##################### Rails ##################################
246
-
247
- Rails/ActionFilter:
248
- Description: 'Enforces consistent use of action filter methods.'
249
- Enabled: true
250
- Rails/Date:
251
- Description: >-
252
- Checks the correct usage of date aware methods,
253
- such as Date.today, Date.current etc.
254
- Enabled: true
255
- Rails/Delegate:
256
- Description: 'Prefer delegate method for delegations.'
257
- Enabled: true
258
- Rails/Exit:
259
- Description: >-
260
- Favor `fail`, `break`, `return`, etc. over `exit` in
261
- application or library code outside of Rake files to avoid
262
- exits during unit testing or running in production.
263
- Enabled: true
264
- Rails/FindBy:
265
- Description: 'Prefer find_by over where.first.'
266
- StyleGuide: 'https://github.com/bbatsov/rails-style-guide#find_by'
267
- Enabled: true
268
- Rails/FindEach:
269
- Description: 'Prefer all.find_each over all.find.'
270
- StyleGuide: 'https://github.com/bbatsov/rails-style-guide#find-each'
271
- Enabled: true
272
- Rails/HasAndBelongsToMany:
273
- Description: 'Prefer has_many :through to has_and_belongs_to_many.'
274
- StyleGuide: 'https://github.com/bbatsov/rails-style-guide#has-many-through'
275
- Enabled: true
276
- Rails/HttpPositionalArguments:
277
- Description: 'Rails 5 only, disabled to keep Hound quiet'
278
- Enabled: false
279
- Rails/NotNullColumn:
280
- Description: 'Do not add a NOT NULL column without a default value'
281
- Enabled: false
282
- Rails/Output:
283
- Description: 'Checks for calls to puts, print, etc.'
284
- Enabled: true
285
- Rails/OutputSafety:
286
- Description: 'The use of `html_safe` or `raw` may be a security risk.'
287
- Enabled: true
288
- Rails/PluralizationGrammar:
289
- Description: 'Checks for incorrect grammar when using methods like `3.day.ago`.'
290
- Enabled: true
291
- Rails/ReadWriteAttribute:
292
- Description: >-
293
- Checks for read_attribute(:attr) and
294
- write_attribute(:attr, val).
295
- StyleGuide: 'https://github.com/bbatsov/rails-style-guide#read-attribute'
296
- Enabled: true
297
- Rails/RequestReferer:
298
- Description: 'Use consistent syntax for request.referer.'
299
- Enabled: true
300
- Rails/SafeNavigation:
301
- Description: "Use Ruby's safe navigation operator (`&.`) instead of `try!`"
302
- Enabled: true
303
- Rails/ScopeArgs:
304
- Description: 'Checks the arguments of ActiveRecord scopes.'
305
- Enabled: true
306
- Rails/TimeZone:
307
- Description: 'Checks the correct usage of time zone aware methods.'
308
- StyleGuide: 'https://github.com/bbatsov/rails-style-guide#time'
309
- Reference: 'http://danilenko.org/2012/7/6/rails_timezones'
310
- Enabled: true
311
- Rails/UniqBeforePluck:
312
- Description: 'Prefer the use of uniq or distinct before pluck.'
313
- Enabled: true
314
- Rails/Validation:
315
- Description: 'Use validates :attribute, hash of validations.'
316
- Enabled: true
317
- Security/JSONLoad:
318
- Description : 'Prefer usage of JSON.parse'
319
- Enabled: true
@@ -1,7 +1,5 @@
1
1
  inherit_from: .hound-rubocop.yml
2
2
 
3
- Rails:
4
- Enabled: true
5
3
  AllCops:
6
4
  TargetRubyVersion: 2.3
7
5
  Exclude:
data/Rakefile CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
  require 'bundler/gem_tasks'
3
3
  require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
4
5
 
5
6
  RSpec::Core::RakeTask.new(:spec)
7
+ RuboCop::RakeTask.new
6
8
 
7
- task default: :spec
9
+ task default: %w(spec rubocop)
@@ -21,7 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ['lib']
23
23
 
24
- spec.add_dependency 'activesupport', '~> 5.0'
25
24
  spec.add_dependency 'savon', '~> 2.11'
26
25
 
27
26
  spec.add_development_dependency 'bundler', '~> 1.14'
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  $LOAD_PATH.unshift File.dirname(__FILE__)
3
3
 
4
- require 'active_support/core_ext/hash/conversions'
5
- require 'active_support/core_ext/hash/slice'
4
+ require 'hash'
6
5
  require 'savon'
7
6
 
8
7
  module Agris
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- # rubocop:disable Rails/TimeZone
3
2
  module Agris
4
3
  module Api
5
4
  class DocumentQueryResponse
@@ -69,7 +69,6 @@ module Agris
69
69
  import_message.message_number,
70
70
  import_message.to_xml
71
71
  )
72
-
73
72
  PostResult.new(response)
74
73
  end
75
74
  end
@@ -10,7 +10,7 @@ module Agris
10
10
  end
11
11
 
12
12
  def error?
13
- ag_error_str_p.present?
13
+ !ag_error_str_p.to_s.strip.empty?
14
14
  end
15
15
 
16
16
  def error_info
@@ -18,7 +18,7 @@ module Agris
18
18
  end
19
19
 
20
20
  def error_hash
21
- @error_hash ||= Hash.from_xml(ag_error_str_p)
21
+ @error_hash ||= error? ? Hash.from_xml(ag_error_str_p) : {}
22
22
  end
23
23
 
24
24
  def output_hash
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Agris
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
@@ -25,8 +25,9 @@ module Agris
25
25
 
26
26
  def to_xml_hash
27
27
  ignore_attributes = (xml_ignore_attributes + [:hash]).map(&:to_s)
28
+ match_attributes = attributes.keys - ignore_attributes
28
29
  attributes
29
- .slice(*(attributes.keys - ignore_attributes))
30
+ .select { |key, _value| match_attributes.include?(key) }
30
31
  .each_with_object({}) do |(name, value), new_hash|
31
32
  new_hash["@#{name.delete('_')}".to_sym] = value
32
33
  new_hash
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nokogiri'
4
+
5
+ class Hash
6
+ class << self
7
+ def from_xml(xml_io)
8
+ result = Nokogiri::XML(xml_io)
9
+
10
+ { key_value(result.root) => xml_node_to_hash(result.root) }
11
+ end
12
+
13
+ protected
14
+
15
+ def xml_node_to_hash(node)
16
+ # If we are at the root of the document, start the hash
17
+ return node.content.to_s unless node.element?
18
+
19
+ result_hash = {}
20
+ if node.attributes != {}
21
+ attributes = {}
22
+ node.attributes.each_key do |key|
23
+ attributes[
24
+ key_value(node.attributes[key])
25
+ ] = node.attributes[key].value
26
+ end
27
+ end
28
+
29
+ return attributes if node.children.empty?
30
+
31
+ node.children.each do |child|
32
+ result = xml_node_to_hash(child)
33
+
34
+ if child.name == 'text'
35
+ unless child.next_sibling || child.previous_sibling
36
+ return result unless attributes
37
+ result_hash[key_value(child)] = result
38
+ end
39
+ elsif result_hash[key_value(child)]
40
+
41
+ if result_hash[key_value(child)].is_a?(Object::Array)
42
+ result_hash[key_value(child)] << result
43
+ else
44
+ result_hash[key_value(child)] = [
45
+ result_hash[key_value(child)]
46
+ ] << result
47
+ end
48
+ else
49
+ result_hash[key_value(child)] = result
50
+ end
51
+ end
52
+ if attributes
53
+ # Add code to remove non-data attributes e.g. xml schema, namespace
54
+ # here, if there is a collision then node content supersets
55
+ # attributes
56
+ result_hash = attributes.merge(result_hash)
57
+ end
58
+ result_hash
59
+ end
60
+
61
+ def key_value(node)
62
+ node.name
63
+ end
64
+ end
65
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agris
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Gray
@@ -9,22 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-07-27 00:00:00.000000000 Z
12
+ date: 2018-02-06 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: '5.0'
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '5.0'
28
14
  - !ruby/object:Gem::Dependency
29
15
  name: savon
30
16
  requirement: !ruby/object:Gem::Requirement
@@ -194,6 +180,7 @@ files:
194
180
  - lib/agris/user_agent.rb
195
181
  - lib/agris/version.rb
196
182
  - lib/agris/xml_model.rb
183
+ - lib/hash.rb
197
184
  homepage: https://github.com/westernmilling/agris.rb
198
185
  licenses:
199
186
  - MIT