diograph-store 0.0.5 → 0.0.6

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
  SHA1:
3
- metadata.gz: 53f5297681d6ff054f516108056e3a6800439d42
4
- data.tar.gz: 82ddcbc2e2eb1db07283c0e65a23b6fabd84b964
3
+ metadata.gz: b0054f8efab8c228ef92b4164c628bc28018d69a
4
+ data.tar.gz: 0a3059151fc239897f0ab3b1a5451810392c95a7
5
5
  SHA512:
6
- metadata.gz: f08a3d6d4d07a13867582cca1a0c79dfaaeb7bf12fa0cb959d46ca3dd12c779092bd44707cecd4aac55f2db83376b9620894b8d8a30a5a0fc2eb580c904fb10f
7
- data.tar.gz: 573766ad639b184c9b9de431333f6b3aa675e742ff20a4548e3f0c89dcfdaf7cc9a7f1f91bfc8d9cc29a0b5a8d690302bb0801ae8f0362560b1bfb018fbbf537
6
+ metadata.gz: a2df9c3f2d38ee75ba3f9f58bdd2f4523a842f6262a462e5427772c151c8840fabb5da84dc1239f7e6cc843680c60dad930ab580bda03f6b61518f7dfaa377fe
7
+ data.tar.gz: d314b3f256b89fab55736547a35cbf0ac0e1137a062d2003ab6c0a0c5477c4d999b2d23bc4e1158b752e9bde7c7d4e1ebd05a17406f1545532a3fb1cfc297256
@@ -0,0 +1,7 @@
1
+ # Diograph Store gem
2
+
3
+ In order to use this, you have to define to ENV's
4
+ ```
5
+ DIOGRAPH_STORE_HOST=http://localhost:3000
6
+ DIOGRAPH_STORE_TOKEN=df548369-d0a2-4ca5-b28a-dd4fb14c1f08
7
+ ```
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './diograph_store/store'
4
- require_relative './diograph_store/diograph_api_request'
3
+ require 'diograph_store/store'
4
+ require 'diograph_store/diograph_api_request'
5
5
  require 'models/room'
6
6
  require 'diograph'
7
7
 
@@ -0,0 +1,23 @@
1
+ module DiographStore
2
+ class Diograph
3
+ def self.diograph_to_diory_api_attributes(diory_diograph)
4
+ {
5
+ "name" => diory_diograph['name'],
6
+ "diory-id" => diory_diograph['ID'],
7
+ "diory-type" => diory_diograph['type'],
8
+ "date" => diory_diograph['date'],
9
+ "address" => diory_diograph['address'],
10
+ "background" => diory_diograph['background'],
11
+ }
12
+ end
13
+
14
+ def self.diograph_to_connection_api_attributes(from_diory_id, connection_diograph)
15
+ {
16
+ "connection-id" => connection_diograph['ID'],
17
+ "from-diory-diory-id" => from_diory_id,
18
+ "to-diory-diory-id" => connection_diograph['diory']['ID'],
19
+ "connection-type" => connection_diograph['connection-type']
20
+ }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pstore'
4
+ require 'models/connection'
5
+
6
+ class ConnectionStore
7
+ attr_reader :store
8
+
9
+ def initialize(object_store=nil)
10
+ @store = PStore.new('./tmp/connections.pstore')
11
+ @object_store = object_store
12
+ end
13
+
14
+ def get(connection_id)
15
+ connection_data = @store.transaction do
16
+ @store[connection_id]
17
+ end
18
+ DiographStore::Connection.new(connection_data, @object_store) unless connection_data.nil?
19
+ end
20
+
21
+ def save(connection_id:, connection_data:)
22
+ @store.transaction do
23
+ @store[connection_id] = connection_data
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pstore'
4
+ require 'diograph_store/connection_store'
5
+
6
+ # Stores only connection ids in PStore
7
+ # - returns Connection objects
8
+ class DioryConnectionStore
9
+ attr_reader :store
10
+
11
+ def initialize
12
+ # Should this be 'diory_connection_ids'
13
+ @store = PStore.new('./tmp/diory_connections.pstore')
14
+ end
15
+
16
+ def get(diory_id)
17
+ diory_connection_ids = @store.transaction do
18
+ @store[diory_id] || []
19
+ end
20
+ end
21
+
22
+ def save(diory_id:, connection_id:)
23
+ @store.transaction do
24
+ # Initialize array if diory doesn't yet have any connection_ids in the store
25
+ if @store[diory_id].nil?
26
+ @store[diory_id] = []
27
+ end
28
+ # Add to array if connection_id doesn't already exist there
29
+ # TODO: Test for trying to add same connection_id again
30
+ unless @store[diory_id].include? connection_id
31
+ @store[diory_id] << connection_id
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pstore'
4
+ require 'models/diory'
5
+ require 'diograph_store/diory_connection_store'
6
+
7
+ class DioryStore
8
+ attr_reader :store
9
+
10
+ def initialize(object_store=nil)
11
+ @store = PStore.new('./tmp/diories.pstore')
12
+ @object_store = object_store
13
+ end
14
+
15
+ def get(diory_id)
16
+ diory_data = @store.transaction do
17
+ @store[diory_id]
18
+ end
19
+
20
+ return if diory_data.nil?
21
+
22
+ # diory_data['connections'] = DioryConnectionStore.new.get(diory_id)
23
+ DiographStore::Diory.new(diory_data, @object_store)
24
+ end
25
+
26
+ def save(diory_id:, diory_data:)
27
+ @store.transaction do
28
+ @store[diory_id] = diory_data
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'diograph_store/diory_store'
4
+
5
+ module DiographStore
6
+ class Connection
7
+ def initialize(connection_data = {}, object_store = DiographStore.new)
8
+ @data = connection_data
9
+ @object_store = object_store
10
+ end
11
+
12
+ def api_id
13
+ @data['id']
14
+ end
15
+
16
+ def id
17
+ connection_id
18
+ end
19
+
20
+ def from_diory
21
+ @object_store.get_diory(from_diory_diory_id)
22
+ end
23
+
24
+ def to_diory
25
+ @object_store.get_diory(to_diory_diory_id)
26
+ end
27
+
28
+ def from_diory_diory_id
29
+ @data['from-diory-diory-id']
30
+ end
31
+
32
+ def to_diory_diory_id
33
+ @data['to-diory-diory-id']
34
+ end
35
+
36
+ def connection_id
37
+ @data['connection-id']
38
+ end
39
+
40
+ def connection_type
41
+ @data['connection-type']
42
+ end
43
+
44
+ def to_diograph
45
+ {
46
+ # "roomID": room_id,
47
+ "ID" => connection_id,
48
+ "connection-type" => connection_type,
49
+ "diory" => { 'ID' => to_diory_diory_id } # to_diory.to_diograph
50
+ }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'diograph_store/diory_connection_store'
4
+
5
+ module DiographStore
6
+ class Diory
7
+ def initialize(diory_data = {}, store = DiographStore.new)
8
+ @data = diory_data
9
+ @store = store
10
+ end
11
+
12
+ def api_id
13
+ @data['id']
14
+ end
15
+
16
+ def id
17
+ diory_id
18
+ end
19
+
20
+ def connections(type: nil)
21
+ diory_connection_ids = DioryConnectionStore.new.get(diory_id)
22
+
23
+ connections = diory_connection_ids.map do |connection_id|
24
+ @store.get_connection(connection_id)
25
+ end
26
+
27
+ return connections if type.nil?
28
+
29
+ connections.select do |a|
30
+ a.connection_type == type
31
+ end
32
+ end
33
+
34
+ def connected_diories(type: nil)
35
+ connections(type: type).map(&:to_diory)
36
+ end
37
+
38
+ def diory_id
39
+ @data['diory-id']
40
+ end
41
+
42
+ def diory_type
43
+ @data['diory-type']
44
+ end
45
+
46
+ def name
47
+ @data['name']
48
+ end
49
+
50
+ def background
51
+ @data['background']
52
+ end
53
+
54
+ def address
55
+ @data['address']
56
+ end
57
+
58
+ def date
59
+ @data['date']
60
+ end
61
+
62
+ def latitude
63
+ @data['latitude']
64
+ end
65
+
66
+ def longitude
67
+ @data['longitude']
68
+ end
69
+
70
+ def created
71
+ @data['created']
72
+ end
73
+
74
+ def modified
75
+ @data['modified']
76
+ end
77
+
78
+ def serialized_properties
79
+ @data['serialized-properties'] || {}
80
+ end
81
+
82
+ def to_diograph
83
+ {
84
+ "ID" => diory_id,
85
+ # "roomID": room_id,
86
+ "name" => name,
87
+ "type" => diory_type,
88
+ "created" => created,
89
+ "modified" => modified,
90
+ "date" => date,
91
+ "address" => address,
92
+ "background" => background,
93
+ "connections" => connections.map(&:to_diograph)
94
+ }
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ module DiographStore
3
+ class Room
4
+ def initialize(room_data = {}) # , object_store = DiographStore.new)
5
+ @data = room_data
6
+ # @object_store = object_store
7
+ end
8
+
9
+ def id
10
+ @data['room-id']
11
+ end
12
+
13
+ def name
14
+ @data['name']
15
+ end
16
+
17
+ # def diories
18
+ # object_store.get_diories(room_id: id)
19
+ # end
20
+
21
+ end
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diograph-store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jouni Alanen
@@ -72,9 +72,17 @@ executables: []
72
72
  extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
+ - README.md
75
76
  - lib/diograph-store.rb
77
+ - lib/diograph.rb
78
+ - lib/diograph_store/connection_store.rb
76
79
  - lib/diograph_store/diograph_api_request.rb
80
+ - lib/diograph_store/diory_connection_store.rb
81
+ - lib/diograph_store/diory_store.rb
77
82
  - lib/diograph_store/store.rb
83
+ - lib/models/connection.rb
84
+ - lib/models/diory.rb
85
+ - lib/models/room.rb
78
86
  homepage: http://dioryme.github.io
79
87
  licenses: []
80
88
  metadata: {}