chronicle-core 0.2.2 → 0.3.1

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