eac_rest 0.8.0 → 0.9.1

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
  SHA256:
3
- metadata.gz: 643d41f4e29430fdc1b49bae8b5f161241cdf6a022af0df70634e9df8dd04999
4
- data.tar.gz: 643c87c4f14cca345437f5cf07fe855e5d804008927a7ef24d945d297af9e9d1
3
+ metadata.gz: 4928b33d7bd23461123a99c7b751c783d9d51ccd913235779741dea434b29825
4
+ data.tar.gz: 23d57beb8de80b2b082c10aaa9788843d16c296d81b959700108c5f73dd00784
5
5
  SHA512:
6
- metadata.gz: 67af3d87c3a01ce868c85c4ff489212e267b6136afa902002340b61ea5f36418a9d0c917fba905d92c84fe6713764988efab1924284cc1788356f6f62e719117
7
- data.tar.gz: 0ed08cabe9f5295ae4c522f6d896e4f31f30522e82dc4a7d9f52a41bd2bf14c8c359611f085c6d4117e893dbb26ac35b1278a2336173755c6c52af260146e0ab
6
+ metadata.gz: eaf826d3d48054a9c3dfb1ae2c39bd2568dfd7474e00c0852b2f6683a82ec82a0995e77ccadc66d36be924b8192187bc419ce79b980e17e890b32441cb42f641
7
+ data.tar.gz: 82cd50f1374a0863b776544c061c42b6053299dca5233592c85a1be79ceb3f30b0fa3d0ac1a33c22c529cc965449ad57693c71660c7167437c5b1c8752ac1ef5
data/lib/eac_rest/api.rb CHANGED
@@ -7,6 +7,8 @@ module EacRest
7
7
  # Abstract methods
8
8
  # * self.issue_get_url_suffix(provider_issue_id)
9
9
  class Api
10
+ DEFAULT_ROOT_ENTITY_CLASS_NAME_SUFFIX = 'Root'
11
+
10
12
  require_sub __FILE__, include_modules: true
11
13
  attr_accessor :ssl_verify
12
14
  common_constructor :root_url, :username, :password, default: [nil, nil] do
@@ -16,8 +18,8 @@ module EacRest
16
18
  # @param entity_class [Class]
17
19
  # @param url_suffix [String]
18
20
  # @return [EacRest::Entity]
19
- def entity(entity_class, url_suffix)
20
- entity_class.new(self, request_json(url_suffix))
21
+ def entity(entity_class, data_or_id, options = {})
22
+ entity_class.new(self, data_or_id, options)
21
23
  end
22
24
 
23
25
  def request(service_url_suffix, headers = {}, &body_data_proc)
@@ -30,7 +32,7 @@ module EacRest
30
32
 
31
33
  def request_json(service_url_suffix, headers = {}, &body_data_proc)
32
34
  request(service_url_suffix, headers.merge('Accept' => 'application/json')) do |body_data|
33
- r = ::JSON.parse(body_data)
35
+ r = body_data.is_a?(::Enumerable) ? body_data : ::JSON.parse(body_data)
34
36
  r = body_data_proc.call(r) if body_data_proc
35
37
  r
36
38
  end
@@ -53,5 +55,15 @@ module EacRest
53
55
  def build_service_url_suffix(suffix)
54
56
  ::Addressable::URI.parse(suffix)
55
57
  end
58
+
59
+ # @return [EacRest::Entity]
60
+ def root_entity
61
+ @root_entity ||= root_entity_class.new(self, nil)
62
+ end
63
+
64
+ # @return [Class]
65
+ def root_entity_class
66
+ self.class.const_get(DEFAULT_ROOT_ENTITY_CLASS_NAME_SUFFIX)
67
+ end
56
68
  end
57
69
  end
@@ -6,7 +6,11 @@ module EacRest
6
6
  class Entity
7
7
  enable_abstract_methods
8
8
  enable_simple_cache
9
- common_constructor :api, :data_or_id
9
+ enable_listable
10
+ lists.add_symbol :option, :parent
11
+ common_constructor :api, :data_or_id, :options, default: [{}] do
12
+ self.options = ::EacRest::Entity.lists.option.hash_keys_validate!(options)
13
+ end
10
14
 
11
15
  class << self
12
16
  def from_array_data(api, array_data, *args)
@@ -14,20 +18,49 @@ module EacRest
14
18
  end
15
19
  end
16
20
 
21
+ # @param entity_class [Class]
22
+ # @param url_suffix [String]
23
+ # @return [EacRest::Entity]
24
+ def child_entity(entity_class, data_or_id, options = {})
25
+ api.entity(entity_class, data_or_id, options.merge(OPTION_PARENT => self))
26
+ end
27
+
17
28
  # @return [Hash]
18
29
  def data
19
- self.data_or_id = data_from_id unless data_or_id_data?
20
- data_or_id
30
+ if internal_data.blank?
31
+ self.internal_data = data_or_id_data? ? data_or_id : data_from_id
32
+ end
33
+
34
+ internal_data
21
35
  end
22
36
 
23
37
  # @return [Boolean]
24
38
  def data_or_id_data?
25
- data_or_id.is?(::Hash)
39
+ data_or_id.is_a?(::Hash)
26
40
  end
27
41
 
28
42
  # @return [Hash]
29
43
  def data_from_id
30
44
  raise_abstract_method __method__
31
45
  end
46
+
47
+ # @return [Object]
48
+ def id
49
+ data_or_id_data? ? id_from_data : data_or_id
50
+ end
51
+
52
+ # @return [Object]
53
+ def id_from_data
54
+ raise_abstract_method __method__
55
+ end
56
+
57
+ # @return [EacRest::Entity, nil]
58
+ def parent_entity
59
+ options[OPTION_PARENT]
60
+ end
61
+
62
+ private
63
+
64
+ attr_accessor :internal_data
32
65
  end
33
66
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRest
4
- VERSION = '0.8.0'
4
+ VERSION = '0.9.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-30 00:00:00.000000000 Z
11
+ date: 2023-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_envs-http
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.3'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 0.3.1
19
+ version: '0.4'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0.3'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 0.3.1
26
+ version: '0.4'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: eac_fs
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -50,14 +44,20 @@ dependencies:
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '0.112'
47
+ version: '0.117'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.117.1
54
51
  type: :runtime
55
52
  prerelease: false
56
53
  version_requirements: !ruby/object:Gem::Requirement
57
54
  requirements:
58
55
  - - "~>"
59
56
  - !ruby/object:Gem::Version
60
- version: '0.112'
57
+ version: '0.117'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.117.1
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: aranha-parsers
63
63
  requirement: !ruby/object:Gem::Requirement