dxlite 0.1.1 → 0.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
2
  SHA256:
3
- metadata.gz: 84d21dac1546d9b48f17180d727090494d5ac56db2c7999d74e153d4a47e1726
4
- data.tar.gz: 27695103757b6213515a77557938b4dcf66074aac72f54ce861987b383e30267
3
+ metadata.gz: 1e0e8b4f265fe12323cca22407f3b06ce13f090192fb0abd83588aa4bd2cf13b
4
+ data.tar.gz: e9b725095dde2698fbd7a6afed799fec375f0d4009901b2021bfad73371ad0cf
5
5
  SHA512:
6
- metadata.gz: ae66f6db210fe79d976432eee366df9d26ed154188c41b96bd8b8732c8904ce4a4b1b9685e810b32b694e36791f613ec8de0b80475db9ccfd5eed493d1374c63
7
- data.tar.gz: 13dfe4016bda0baeaef29d7e118e1003a19297f21530ba19f7543e9579b1403f3846cc288e6fb259288765b8615e47c5ca5cc7eec227dbc599403093715de32d
6
+ metadata.gz: 439ffafee850ff7f07dd8915099c97cc24f4f9914780ce03231a57f200b43a734c3ebafeaa49d21f0b850a25bd5ce34b505e669bfac55bd911ea26c343313e6f
7
+ data.tar.gz: 370a4daca23b52c6a0b2e06c9abcd653cb061e14d93dfd4195250f41cb8c6b220261388f9812ee977bfe09963c37f7a1d3ef3fc7f20b9dc110f2fccfcdbedd0d
@@ -1,4 +1,2 @@
1
- 4�����^�*fD���6�����%zQT�7:�F�~yOUOD�گ-(�+YڼU�H�����L�#�����I.8FGZ���`z�w�F�j5iԅ�m�<�u��$R0.h �&U*˞\����O���BK~��G
2
- �[����f��#5�q�BI��2nP����~���ɭ'>F���ǥUE 0���P3E���ؙ;=˩�ͭI���(�A��
3
- B��D(��T��e��.�_�o.L�yZ�f���L�����M$#\�t�
4
- 멭�^��F�Œ�gG�Ӵ��:&�:k�d{OĂ'!\"�3��������M��5�T.G��nJ�;4o�p:3��~�-�
1
+ `�����$yΨìib���v*�0����/����8��Ж-���\75���uܥ��~������1���_��T�����<��e/Y�?E>�k��GA��~�H��!J:�z�Dxm_z_[�f��a`o����.TP�ͨ{��f��/�1'�ɩ9iV��^o�5����k=r�����al�ƽHjT��������V�ƝL�Җv�& Z�a<3���J���~g����ܳ?�k/Z|w4�ö��R�8��x����A~�]#Hg8%5�ȷ�z7��
2
+  ��<_�[h8���3�4>��-������,�<=�\X\�8 �~���KK���@�����ЛjzIJR��� �q=|���$�\<��|@���
data.tar.gz.sig CHANGED
Binary file
@@ -2,11 +2,13 @@
2
2
 
3
3
  # file: dxlite.rb
4
4
 
5
+ require 'c32'
5
6
  require 'json'
6
7
  require 'recordx'
7
8
  require 'rxfhelper'
8
9
 
9
10
  class DxLite
11
+ using ColouredText
10
12
 
11
13
  attr_accessor :summary
12
14
  attr_reader :records
@@ -17,12 +19,41 @@ class DxLite
17
19
 
18
20
  buffer, type = RXFHelper.read(s)
19
21
  puts 'type: ' + type.inspect if @debug
20
- h = JSON.parse(buffer, symbolize_names: true)
21
-
22
- @filepath = s if type == :file
23
-
24
- @summary = h[:summary]
25
- @records = h[:records]
22
+
23
+ case type
24
+
25
+ when :file
26
+
27
+ h = JSON.parse(buffer, symbolize_names: true)
28
+ @filepath = s
29
+
30
+ @summary = h[:summary]
31
+ @records = h[:records]
32
+
33
+ when :text
34
+
35
+ @summary = {schema: s}
36
+ @records = []
37
+
38
+ end
39
+
40
+ @schema = @summary[:schema]
41
+
42
+ @summary.merge! @summary[:schema][/(?<=\[)[^\]]+/].split(',')\
43
+ .map {|x|[x.strip, nil] }.to_h
44
+
45
+ # for each summary item create get and set methods
46
+
47
+ @summary.each do |key, value|
48
+
49
+ define_singleton_method(key) { @summary[key] }
50
+
51
+ define_singleton_method (key.to_s + '=').to_sym do |value|
52
+ @summary[key] = value
53
+ end
54
+
55
+ end
56
+
26
57
  @fields = @summary[:schema][/(?<=\()[^\)]+/].split(',').map(&:strip)
27
58
 
28
59
  @fields.each do |x|
@@ -42,7 +73,7 @@ class DxLite
42
73
  def all()
43
74
 
44
75
  @records.map do |h|
45
- RecordX.new(h, self, h[:id], h[:created], h[:last_modified])
76
+ RecordX.new(h, self, h.object_id, h[:created], h[:last_modified])
46
77
  end
47
78
 
48
79
  end
@@ -50,9 +81,43 @@ class DxLite
50
81
  def create(h)
51
82
  @records << h
52
83
  end
84
+
85
+ # Parses 1 or more lines of text to create or update existing records.
86
+
87
+ def parse(obj=nil)
88
+
89
+ if obj.is_a? Array then
90
+
91
+ unless schema() then
92
+ cols = obj.first.keys.map {|c| c == 'id' ? 'uid' : c}
93
+ self.schema = "items/item(%s)" % cols.join(', ')
94
+ end
95
+
96
+ obj.each {|x| self.create x }
97
+ return self
98
+
99
+ end
100
+ end
101
+
102
+ alias import parse
53
103
 
54
104
  def save(file=@filepath)
55
105
  File.write file, @records.to_json
56
106
  end
57
107
 
108
+ # Updates a record from an id and a hash containing field name and field value.
109
+ # dynarex.update 4, name: Jeff, age: 38
110
+
111
+ def update(id, obj)
112
+
113
+ if @debug then
114
+ puts 'inside update'.info
115
+ puts ('id: ' + id.inspect).debug
116
+ puts ('obj.class: ' + obj.class.inspect).debug
117
+ end
118
+
119
+ r = @records.find {|x| x.object_id == id}
120
+ r.merge!(obj)
121
+ end
122
+
58
123
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dxlite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  dwbAN6/wokoLVZAiMRG1vZlI6RhtSOTHvFHbfBE5JI9rhjRtui8yeV+t8iI8G4Zs
36
36
  2NszuYzdlVfzlrUiPWY5jL9P
37
37
  -----END CERTIFICATE-----
38
- date: 2020-06-20 00:00:00.000000000 Z
38
+ date: 2020-06-21 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: recordx
@@ -46,7 +46,7 @@ dependencies:
46
46
  version: '0.5'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 0.5.4
49
+ version: 0.5.5
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
@@ -56,7 +56,7 @@ dependencies:
56
56
  version: '0.5'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 0.5.4
59
+ version: 0.5.5
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: rxfhelper
62
62
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file