terrestrial 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +5 -5
  2. data/.ruby-version +1 -1
  3. data/Gemfile.lock +44 -53
  4. data/README.md +3 -6
  5. data/bin/test +1 -1
  6. data/features/env.rb +12 -2
  7. data/features/example.feature +23 -26
  8. data/lib/terrestrial.rb +31 -0
  9. data/lib/terrestrial/adapters/abstract_adapter.rb +6 -0
  10. data/lib/terrestrial/adapters/memory_adapter.rb +82 -6
  11. data/lib/terrestrial/adapters/sequel_postgres_adapter.rb +191 -0
  12. data/lib/terrestrial/configurations/conventional_association_configuration.rb +65 -35
  13. data/lib/terrestrial/configurations/conventional_configuration.rb +280 -124
  14. data/lib/terrestrial/configurations/mapping_config_options_proxy.rb +97 -0
  15. data/lib/terrestrial/deleted_record.rb +12 -8
  16. data/lib/terrestrial/dirty_map.rb +17 -9
  17. data/lib/terrestrial/functional_pipeline.rb +64 -0
  18. data/lib/terrestrial/inspection_string.rb +6 -1
  19. data/lib/terrestrial/lazy_object_proxy.rb +1 -0
  20. data/lib/terrestrial/many_to_many_association.rb +34 -20
  21. data/lib/terrestrial/many_to_one_association.rb +11 -3
  22. data/lib/terrestrial/one_to_many_association.rb +9 -0
  23. data/lib/terrestrial/public_conveniencies.rb +65 -82
  24. data/lib/terrestrial/record.rb +106 -0
  25. data/lib/terrestrial/relation_mapping.rb +43 -12
  26. data/lib/terrestrial/relational_store.rb +33 -11
  27. data/lib/terrestrial/upsert_record.rb +54 -0
  28. data/lib/terrestrial/version.rb +1 -1
  29. data/spec/automatic_timestamps_spec.rb +339 -0
  30. data/spec/changes_api_spec.rb +81 -0
  31. data/spec/config_override_spec.rb +28 -19
  32. data/spec/custom_serializers_spec.rb +3 -2
  33. data/spec/database_default_fields_spec.rb +213 -0
  34. data/spec/database_generated_id_spec.rb +291 -0
  35. data/spec/database_owned_fields_and_timestamps_spec.rb +200 -0
  36. data/spec/deletion_spec.rb +1 -1
  37. data/spec/error_handling/factory_error_handling_spec.rb +1 -4
  38. data/spec/error_handling/serialization_error_spec.rb +1 -4
  39. data/spec/error_handling/upsert_error_spec.rb +7 -11
  40. data/spec/graph_persistence_spec.rb +52 -18
  41. data/spec/ordered_association_spec.rb +10 -12
  42. data/spec/predefined_queries_spec.rb +14 -12
  43. data/spec/readme_examples_spec.rb +1 -1
  44. data/spec/sequel_query_efficiency_spec.rb +19 -16
  45. data/spec/spec_helper.rb +6 -1
  46. data/spec/support/blog_schema.rb +7 -3
  47. data/spec/support/object_graph_setup.rb +30 -39
  48. data/spec/support/object_store_setup.rb +16 -196
  49. data/spec/support/seed_data_setup.rb +15 -149
  50. data/spec/support/seed_records.rb +141 -0
  51. data/spec/support/sequel_test_support.rb +46 -13
  52. data/spec/terrestrial/abstract_record_spec.rb +138 -106
  53. data/spec/terrestrial/adapters/sequel_postgres_adapter_spec.rb +138 -0
  54. data/spec/terrestrial/deleted_record_spec.rb +0 -27
  55. data/spec/terrestrial/dirty_map_spec.rb +52 -77
  56. data/spec/terrestrial/functional_pipeline_spec.rb +153 -0
  57. data/spec/terrestrial/inspection_string_spec.rb +61 -0
  58. data/spec/terrestrial/upsert_record_spec.rb +29 -0
  59. data/terrestrial.gemspec +7 -8
  60. metadata +43 -40
  61. data/MissingFeatures.md +0 -64
  62. data/lib/terrestrial/abstract_record.rb +0 -99
  63. data/lib/terrestrial/association_loaders.rb +0 -52
  64. data/lib/terrestrial/upserted_record.rb +0 -15
  65. data/spec/terrestrial/public_conveniencies_spec.rb +0 -63
  66. data/spec/terrestrial/upserted_record_spec.rb +0 -59
@@ -1,52 +0,0 @@
1
- module Terrestrial
2
- module AssociationLoaders
3
- class OneToMany
4
- def initialize(type:, mapping_name:, foreign_key:, key:, proxy_factory:)
5
- @type = type
6
- @mapping_name = mapping_name
7
- @foreign_key = foreign_key
8
- @key = key
9
- @proxy_factory = proxy_factory
10
- @eager_loads = {}
11
- end
12
-
13
- attr_reader :type, :mapping_name, :foreign_key, :key, :proxy_factory
14
- private :type, :mapping_name, :foreign_key, :key, :proxy_factory
15
-
16
- def fetch(*args, &block)
17
- {
18
- key: key,
19
- foreign_key: foreign_key,
20
- type: type,
21
- mapping_name: mapping_name,
22
- }.fetch(*args, &block)
23
- end
24
-
25
- def call(mappings, record, &object_pipeline)
26
- mapping = mappings.fetch(mapping_name)
27
-
28
- proxy_factory.call(
29
- query: query(mapping, record),
30
- loader: object_pipeline.call(mapping),
31
- association_loader: self,
32
- )
33
- end
34
-
35
- def query(mapping, record)
36
- foreign_key_value = record.fetch(key)
37
-
38
- ->(datastore) {
39
- @eager_loads.fetch(record) {
40
- datastore[mapping.namespace]
41
- .where(foreign_key => foreign_key_value)
42
- }
43
- }
44
- end
45
-
46
- def eager_load(dataset, association_name)
47
- datastore[mapping.namespace]
48
- .where(foreign_key => dataset.select(key))
49
- end
50
- end
51
- end
52
- end
@@ -1,15 +0,0 @@
1
- require "terrestrial/abstract_record"
2
-
3
- module Terrestrial
4
- class UpsertedRecord < AbstractRecord
5
- def if_upsert(&block)
6
- block.call(self)
7
- self
8
- end
9
-
10
- protected
11
- def operation
12
- :upsert
13
- end
14
- end
15
- end
@@ -1,63 +0,0 @@
1
- require "spec_helper"
2
-
3
- require "terrestrial/public_conveniencies"
4
- require "ostruct"
5
-
6
- RSpec.describe Terrestrial::PublicConveniencies do
7
- subject(:conveniences) {
8
- Module.new.extend(Terrestrial::PublicConveniencies)
9
- }
10
-
11
- class MockDatastore < DelegateClass(Hash)
12
- def transaction(&block)
13
- block.call
14
- end
15
- end
16
-
17
- describe "#object_store" do
18
- let(:datastore) {
19
- MockDatastore.new(
20
- {
21
- things: [ thing_record ],
22
- }
23
- )
24
- }
25
-
26
- let(:mappings) {
27
- {
28
- things: double(
29
- :thing_config,
30
- name: mapping_name,
31
- namespace: :things,
32
- fields: [:id],
33
- associations: [],
34
- primary_key: [],
35
- load: thing_object,
36
- )
37
- }
38
- }
39
-
40
- let(:mapping_name) { :things }
41
-
42
- let(:thing_record) {
43
- {
44
- id: "THE THING",
45
- }
46
- }
47
-
48
- let(:thing_object) {
49
- OpenStruct.new(thing_record)
50
- }
51
-
52
- it "returns an object store for given mappings" do
53
- object_store = conveniences.object_store(
54
- mappings: mappings,
55
- datastore: datastore,
56
- )
57
-
58
- expect(
59
- object_store[:things].all.first.id
60
- ).to eq("THE THING")
61
- end
62
- end
63
- end
@@ -1,59 +0,0 @@
1
- require "spec_helper"
2
-
3
- require "terrestrial/upserted_record"
4
-
5
- RSpec.describe Terrestrial::UpsertedRecord do
6
- subject(:record) {
7
- Terrestrial::UpsertedRecord.new(namespace, identity, raw_data)
8
- }
9
-
10
- let(:namespace) { double(:namespace) }
11
-
12
- let(:identity) {
13
- { id: id }
14
- }
15
-
16
- let(:raw_data) {
17
- {
18
- name: name,
19
- }
20
- }
21
-
22
- let(:id) { double(:id) }
23
- let(:name) { double(:name) }
24
-
25
- describe "#if_upsert" do
26
- it "invokes the callback" do
27
- expect { |callback|
28
- record.if_upsert(&callback)
29
- }.to yield_with_args(record)
30
- end
31
- end
32
-
33
- describe "#==" do
34
- context "with another record that upserts" do
35
- let(:comparitor) {
36
- record.merge({})
37
- }
38
-
39
- it "is equal" do
40
- expect(record.==(comparitor)).to be(true)
41
- end
42
- end
43
-
44
- context "with another record that does not upsert" do
45
- let(:comparitor) {
46
- Class.new(Terrestrial::AbstractRecord) do
47
- protected
48
- def operation
49
- :something_else
50
- end
51
- end
52
- }
53
-
54
- it "is not equal" do
55
- expect(record.==(comparitor)).to be(false)
56
- end
57
- end
58
- end
59
- end