economic-rest 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16253a4130aa087298e4c6f1261312c3699d5083c56621432c0c60a36b49a289
4
- data.tar.gz: cf0c7806cf4520d1cc6351897e9aed8487d68af7d16480ba00b8fc84b2f75c0c
3
+ metadata.gz: d5bb0d48dd081895b21a673c69be152779d24bb7c69573d3700a059242410dca
4
+ data.tar.gz: 381297d78b417851357fee249ab2c86af0f9cba81c1d3adc7cceb2026d08bc29
5
5
  SHA512:
6
- metadata.gz: ddce2e12d68616df71c6808f47ef79d357eca180e9b43cdf5db5441287bb785637f2eb3bcbbb39f6246c1c46fc7b56ed30c54008f41d0af8c0bbd4472cdf8172
7
- data.tar.gz: e2fc8f32dcdd3e0d1d82e8aebd1e6800a362e695be9b4d842b831bc3f3a6cd7d5f31a038f7148a8195f98627957a20f07c168d993a9b36fcb0b7bb0782a117c9
6
+ metadata.gz: bc1637c6c5f36d3a47639635c12c1d91e80b04334808e4644e59fecacd6e011d1ca5821650af46700fef5eeef101b168fc5f3fabde3a7301ece1b12d8ec80f51
7
+ data.tar.gz: e85e9e5e8bc902af85a57dd9d92f85976bfe9c4ec02b99b30df0cdc478f26058ed7f4b6e18ad8be48052e16801b6a97c565a68c00207c7948d2034c518cec6db
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- economic-rest (0.1.7)
4
+ economic-rest (0.1.8)
5
5
  rest-client
6
6
 
7
7
  GEM
@@ -0,0 +1,5 @@
1
+ module Economic
2
+ class AccountingYear < Base
3
+ field :year
4
+ end
5
+ end
data/lib/economic/base.rb CHANGED
@@ -26,6 +26,15 @@ module Economic
26
26
  end
27
27
  end
28
28
 
29
+ def self.relation(name, fields:)
30
+ related_model = Object.const_get('Economic::' + name.slice(0, 1).capitalize + name.slice(1..-1)).new({})
31
+ define_method(name) do
32
+ @internal_hash[name] = related_model.to_h(fields: fields)
33
+ related_model
34
+ end
35
+ alias_method snake_case(name), name
36
+ end
37
+
29
38
  def values_based_on_hash(hash)
30
39
  Hash.class_eval { include ExtraMethods }
31
40
  @internal_hash = hash
@@ -44,10 +53,21 @@ module Economic
44
53
  end
45
54
  end
46
55
 
47
- def to_h
56
+ def to_h(fields: [])
48
57
  self.class.attributes.each do |attribute|
49
58
  @internal_hash[attribute.to_sym] = send(attribute) unless send(attribute).nil?
50
59
  end
60
+ @internal_hash.each do |k, _v|
61
+ send(k) if respond_to? k
62
+ end
63
+ unless fields.empty?
64
+ # because we have field we should only return those values from the hash
65
+ limited_hash = {}
66
+ fields.each do |field|
67
+ limited_hash[field.to_sym] = send(field) unless send(field).nil?
68
+ end
69
+ return limited_hash
70
+ end
51
71
  @internal_hash
52
72
  end
53
73
 
@@ -1,5 +1,5 @@
1
1
  module Economic
2
2
  module Rest
3
- VERSION = '0.1.8'.freeze
3
+ VERSION = '0.1.9'.freeze
4
4
  end
5
5
  end
data/lib/economic/rest.rb CHANGED
@@ -17,6 +17,7 @@ require 'economic/orders/sent_repo'
17
17
  require 'economic/journal_repo'
18
18
  require 'economic/journal'
19
19
 
20
+ require 'economic/accounting_year'
20
21
  require 'economic/voucher'
21
22
 
22
23
  module Economic
@@ -2,10 +2,9 @@ module Economic
2
2
  class Voucher < Base
3
3
  field :voucherNumber, id: true
4
4
 
5
- field :accountingYear
6
5
  field :entries
7
6
  field :journal
8
7
 
9
- #relation:
8
+ relation :accountingYear, fields: [:year]
10
9
  end
11
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: economic-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Klogborg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-01 00:00:00.000000000 Z
11
+ date: 2019-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,6 +97,7 @@ files:
97
97
  - bin/console
98
98
  - bin/setup
99
99
  - economic-rest.gemspec
100
+ - lib/economic/accounting_year.rb
100
101
  - lib/economic/base.rb
101
102
  - lib/economic/base_repo.rb
102
103
  - lib/economic/customer.rb