chronicle-core 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +1 -1
- data/.gitignore +3 -1
- data/.rubocop-plugin.yml +4 -0
- data/.rubocop.yml +16 -2
- data/Gemfile +2 -2
- data/Guardfile +3 -3
- data/LICENSE.txt +1 -1
- data/README.md +87 -2
- data/Rakefile +63 -1
- data/bin/console +6 -6
- data/chronicle-core.gemspec +32 -26
- data/lib/chronicle/core/version.rb +1 -3
- data/lib/chronicle/core.rb +1 -3
- data/lib/chronicle/models/base.rb +96 -0
- data/lib/chronicle/models/builder.rb +35 -0
- data/lib/chronicle/models/generation.rb +89 -0
- data/lib/chronicle/models/model_factory.rb +63 -0
- data/lib/chronicle/models.rb +17 -0
- data/lib/chronicle/schema/rdf_parsing/graph_transformer.rb +122 -0
- data/lib/chronicle/schema/rdf_parsing/rdf_serializer.rb +138 -0
- data/lib/chronicle/schema/rdf_parsing/schemaorg.rb +50 -0
- data/lib/chronicle/schema/rdf_parsing/ttl_graph_builder.rb +142 -0
- data/lib/chronicle/schema/rdf_parsing.rb +11 -0
- data/lib/chronicle/schema/schema_graph.rb +145 -0
- data/lib/chronicle/schema/schema_property.rb +81 -0
- data/lib/chronicle/schema/schema_type.rb +110 -0
- data/lib/chronicle/schema/types.rb +9 -0
- data/lib/chronicle/schema/validation/base_contract.rb +22 -0
- data/lib/chronicle/schema/validation/contract_factory.rb +133 -0
- data/lib/chronicle/schema/validation/edge_validator.rb +53 -0
- data/lib/chronicle/schema/validation/generation.rb +29 -0
- data/lib/chronicle/schema/validation/validator.rb +23 -0
- data/lib/chronicle/schema/validation.rb +41 -0
- data/lib/chronicle/schema.rb +9 -2
- data/lib/chronicle/serialization/hash_serializer.rb +5 -11
- data/lib/chronicle/serialization/jsonapi_serializer.rb +41 -26
- data/lib/chronicle/serialization/jsonld_serializer.rb +38 -0
- data/lib/chronicle/serialization/record.rb +90 -0
- data/lib/chronicle/serialization/serializer.rb +31 -18
- data/lib/chronicle/serialization.rb +6 -4
- data/lib/chronicle/utils/hash_utils.rb +19 -16
- data/schema/chronicle_schema_v1.json +1008 -0
- data/schema/chronicle_schema_v1.rb +147 -0
- data/schema/chronicle_schema_v1.ttl +562 -0
- metadata +107 -15
- data/lib/chronicle/schema/activity.rb +0 -5
- data/lib/chronicle/schema/base.rb +0 -79
- data/lib/chronicle/schema/entity.rb +0 -5
- data/lib/chronicle/schema/raw.rb +0 -9
- data/lib/chronicle/schema/validator.rb +0 -55
@@ -1,24 +1,37 @@
|
|
1
|
-
module Chronicle
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
module Chronicle
|
2
|
+
module Serialization
|
3
|
+
class Serializer
|
4
|
+
# Construct a new instance of this serializer.
|
5
|
+
# == Parameters:
|
6
|
+
# options::
|
7
|
+
# Options for configuring this Serializers
|
8
|
+
def initialize(record, options = {})
|
9
|
+
unless record.is_a?(Chronicle::Serialization::Record)
|
10
|
+
raise(ArgumentError,
|
11
|
+
"Must be a Record. It is a: #{record.class}")
|
12
|
+
end
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
14
|
+
@record = record
|
15
|
+
@options = options
|
16
|
+
end
|
13
17
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
# Serialize a record as a hash
|
19
|
+
def serializable_hash
|
20
|
+
raise NotImplementedError
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.serialize(data)
|
24
|
+
record = if data.is_a?(Chronicle::Models::Base)
|
25
|
+
Chronicle::Serialization::Record.build_from_model(data)
|
26
|
+
elsif data.is_a?(Chronicle::Serialization::Record)
|
27
|
+
data
|
28
|
+
else
|
29
|
+
raise ArgumentError, 'data must be a Chronicle::Models::Base or Chronicle::Serialization::Record'
|
30
|
+
end
|
18
31
|
|
19
|
-
|
20
|
-
|
21
|
-
|
32
|
+
serializer = new(record)
|
33
|
+
serializer.serializable_hash
|
34
|
+
end
|
22
35
|
end
|
23
36
|
end
|
24
37
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'chronicle/schema'
|
2
2
|
|
3
3
|
module Chronicle
|
4
4
|
module Serialization
|
@@ -8,6 +8,8 @@ module Chronicle
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
require_relative
|
12
|
-
require_relative
|
13
|
-
require_relative
|
11
|
+
require_relative 'serialization/record'
|
12
|
+
require_relative 'serialization/serializer'
|
13
|
+
require_relative 'serialization/hash_serializer'
|
14
|
+
require_relative 'serialization/jsonapi_serializer'
|
15
|
+
require_relative 'serialization/jsonld_serializer'
|
@@ -1,23 +1,26 @@
|
|
1
|
-
module Chronicle
|
2
|
-
module
|
3
|
-
|
4
|
-
hash
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
module Chronicle
|
2
|
+
module Utils
|
3
|
+
module HashUtils
|
4
|
+
def self.flatten_hash(hash, parent_key = '', result = {})
|
5
|
+
hash.each do |key, value|
|
6
|
+
current_key = parent_key + (parent_key.empty? ? '' : '.') + key.to_s
|
7
|
+
case value
|
8
|
+
when Hash
|
9
|
+
flatten_hash(value, current_key, result)
|
10
|
+
when Array
|
11
|
+
value.each_with_index do |item, index|
|
12
|
+
if item.is_a?(Hash)
|
13
|
+
flatten_hash(item, "#{current_key}[#{index}]", result)
|
14
|
+
else
|
15
|
+
result["#{current_key}[#{index}]".to_sym] = item
|
16
|
+
end
|
14
17
|
end
|
18
|
+
else
|
19
|
+
result[current_key.to_sym] = value
|
15
20
|
end
|
16
|
-
else
|
17
|
-
result[current_key.to_sym] = value
|
18
21
|
end
|
22
|
+
result
|
19
23
|
end
|
20
|
-
result
|
21
24
|
end
|
22
25
|
end
|
23
26
|
end
|