lhs 11.3.3 → 12.0.0

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: b17c90e65dafbd6cc36a2e8ebfead0e7abee819c
4
- data.tar.gz: 8ad952d7bebb07cfdb417dd5db4519cac2a80dbc
3
+ metadata.gz: 2fc72f0094042042734fdecaec1df8b9c07194a2
4
+ data.tar.gz: 33bc6824ba84ac62a79a7c2cc324f61681789847
5
5
  SHA512:
6
- metadata.gz: 40d3b01be43d424b9e2b19d7ad029b5e985988bcebcfa324e932836f8d608993f195eb93ee10ed2f77ea95bcab1c15fec3a3bfba7bbd3e8fdc180bd7dff7e16a
7
- data.tar.gz: b8207ba3f7623a428faa2904c70514b3cc37afbc40a131be76e2c07018cb65f9ed4d364b229db7351fb16ecc899fe8f4df6aef32eb41085bffa1937a3041f1a5
6
+ metadata.gz: 4f90bef44098ed8a70f00285c48c7627774a1cc00d3a04b5f2030855c7ee5807597cc9e920ea91f9307aca1980fd77927345e70f8826a11b787590e2caba4761
7
+ data.tar.gz: 7488e69922acb478161effd760e6ae5224c0d192ed1f4bd7fd78a4bdd578fd945e057af4e058a9183bdc88dc58e81beeaa563b2c50334535c9796886ca37c832
data/lib/lhs.rb CHANGED
@@ -1,40 +1,49 @@
1
1
  require 'lhc'
2
- Dir[File.dirname(__FILE__) + '/lhs/concerns/lhs/*.rb'].sort.each { |file| require file }
3
2
 
4
3
  module LHS
5
- include Configuration
6
- class RequireLhsRecords
7
- def initialize(app)
8
- @app = app
9
- end
10
-
11
- def call(env)
12
- self.class.require_records
13
- @app.call(env)
14
- end
15
-
16
- def self.require_records
17
- Dir.glob(Rails.root.join('app/models/**/*.rb')).each do |file|
18
- require_dependency file if File.read(file).match('LHS::Record')
19
- end
20
- end
4
+ autoload :Configuration,
5
+ 'lhs/concerns/configuration'
6
+ autoload :AutoloadRecords,
7
+ 'lhs/concerns/autoload_records'
8
+ autoload :Collection,
9
+ 'lhs/collection'
10
+ autoload :Complex,
11
+ 'lhs/complex'
12
+ autoload :Config,
13
+ 'lhs/config'
14
+ autoload :Data,
15
+ 'lhs/data'
16
+ autoload :Endpoint,
17
+ 'lhs/endpoint'
18
+ autoload :Errors,
19
+ 'lhs/errors/base'
20
+ module Errors
21
+ autoload :Nested,
22
+ 'lhs/errors/nested'
21
23
  end
22
- end
23
-
24
- Gem.find_files('lhs/**/*.rb')
25
- .sort
26
- .reject do |path|
27
- (!defined?(Rails) && File.basename(path).include?('railtie.rb')) # don't require railtie if Rails is not around
28
- end.each do |path|
29
- require path
24
+ autoload :Inspect,
25
+ 'lhs/concerns/inspect'
26
+ autoload :Item,
27
+ 'lhs/item'
28
+ autoload :Pagination,
29
+ 'lhs/pagination/base'
30
+ module Pagination
31
+ autoload :Offset,
32
+ 'lhs/pagination/offset'
33
+ autoload :Page,
34
+ 'lhs/pagination/page'
35
+ autoload :Start,
36
+ 'lhs/pagination/start'
30
37
  end
38
+ autoload :Proxy,
39
+ 'lhs/proxy'
40
+ autoload :Record,
41
+ 'lhs/record'
42
+
43
+ include Configuration
44
+ include AutoloadRecords
31
45
 
32
- # Preload all the LHS::Records that are defined in app/models
33
- class Engine < Rails::Engine
34
- initializer 'Load all LHS::Records from app/models/**' do |app|
35
- LHS::RequireLhsRecords.require_records
36
- next if app.config.cache_classes
46
+ require 'lhs/record' # as lhs records in an application are directly inheriting it
37
47
 
38
- app.config.middleware.use LHS::RequireLhsRecords
39
- end
48
+ require 'lhs/railtie' if defined?(Rails)
40
49
  end
@@ -1,9 +1,7 @@
1
- require File.join(__dir__, 'proxy.rb')
2
- Dir[File.dirname(__FILE__) + '/concerns/collection/*.rb'].each { |file| require file }
3
-
4
1
  # A collection is a special type of data
5
2
  # that contains multiple items
6
3
  class LHS::Collection < LHS::Proxy
4
+ autoload :InternalCollection, 'lhs/concerns/collection/internal_collection'
7
5
  include InternalCollection
8
6
  include Create
9
7
 
@@ -0,0 +1,36 @@
1
+ require 'active_support'
2
+
3
+ # Preload all the LHS::Records that are defined in app/models/*
4
+ # in order to collect record endpoints and to be able to identify records from hrefs
5
+ # and not only from model constant names (which is different to ActiveRecord)
6
+ module AutoloadRecords
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ class Engine < Rails::Engine
11
+ initializer 'Load all LHS::Records from app/models/**' do |app|
12
+ Middleware.require_records
13
+ next if app.config.cache_classes
14
+
15
+ app.config.middleware.use Middleware
16
+ end
17
+
18
+ class Middleware
19
+ def initialize(app)
20
+ @app = app
21
+ end
22
+
23
+ def call(env)
24
+ self.class.require_records
25
+ @app.call(env)
26
+ end
27
+
28
+ def self.require_records
29
+ Dir.glob(Rails.root.join('app/models/**/*.rb')).each do |file|
30
+ require_dependency file if File.read(file).match('LHS::Record')
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,5 +1,4 @@
1
1
  require 'active_support'
2
- require File.dirname(__FILE__) + '/../../proxy'
3
2
 
4
3
  class LHS::Collection < LHS::Proxy
5
4
 
@@ -1,66 +1,68 @@
1
1
  require 'active_support'
2
2
 
3
- module Inspect
4
- extend ActiveSupport::Concern
3
+ module LHS
4
+ module Inspect
5
+ extend ActiveSupport::Concern
5
6
 
6
- def inspect
7
- [
7
+ def inspect
8
8
  [
9
9
  [
10
10
  [
11
- to_s.match('LHS::Data') ? 'Data of ' : nil,
12
- self.class
13
- ].join,
14
- _inspect_id
15
- ].join(' '),
16
- _inspect_path
17
- ].compact.join("\n"),
18
- pretty_raw
19
- ].compact.join("\n")
20
- end
11
+ [
12
+ to_s.match('LHS::Data') ? 'Data of ' : nil,
13
+ self.class
14
+ ].join,
15
+ _inspect_id
16
+ ].join(' '),
17
+ _inspect_path
18
+ ].compact.join("\n"),
19
+ pretty_raw
20
+ ].compact.join("\n")
21
+ end
21
22
 
22
- private
23
+ private
23
24
 
24
- def _inspect_id
25
- _root.href || (_root.item? ? _root.id : nil) || object_id
26
- end
25
+ def _inspect_id
26
+ _root.href || (_root.item? ? _root.id : nil) || object_id
27
+ end
27
28
 
28
- def _inspect_path
29
- current = self
30
- path = []
31
- _collect_parents_for_inspect!(path, current)
32
- return unless path.present?
33
- "> #{path.reverse.join(' > ')}"
34
- end
29
+ def _inspect_path
30
+ current = self
31
+ path = []
32
+ _collect_parents_for_inspect!(path, current)
33
+ return unless path.present?
34
+ "> #{path.reverse.join(' > ')}"
35
+ end
35
36
 
36
- def _collect_parents_for_inspect!(path, current)
37
- return unless current.parent
38
- parent_raw = current.parent._raw
39
- if parent_raw.is_a?(Array)
40
- parent_raw.each_with_index do |element, index|
41
- path.push(index) if element == current._raw
42
- end
43
- elsif parent_raw.is_a?(Hash)
44
- parent_raw.each do |key, value|
45
- path.push(key) if value == current._raw
37
+ def _collect_parents_for_inspect!(path, current)
38
+ return unless current.parent
39
+ parent_raw = current.parent._raw
40
+ if parent_raw.is_a?(Array)
41
+ parent_raw.each_with_index do |element, index|
42
+ path.push(index) if element == current._raw
43
+ end
44
+ elsif parent_raw.is_a?(Hash)
45
+ parent_raw.each do |key, value|
46
+ path.push(key) if value == current._raw
47
+ end
46
48
  end
49
+ _collect_parents_for_inspect!(path, current.parent)
47
50
  end
48
- _collect_parents_for_inspect!(path, current.parent)
49
- end
50
51
 
51
- def pretty_raw
52
- return if _raw.blank?
53
- if _raw.is_a?(Array)
54
- _raw
55
- else
56
- _raw.to_a.map do |key, value|
57
- ":#{key} => " +
58
- if value.is_a? String
59
- "\"#{value}\""
60
- else
61
- value.to_s
62
- end
63
- end
64
- end.join("\n")
52
+ def pretty_raw
53
+ return if _raw.blank?
54
+ if _raw.is_a?(Array)
55
+ _raw
56
+ else
57
+ _raw.to_a.map do |key, value|
58
+ ":#{key} => " +
59
+ if value.is_a? String
60
+ "\"#{value}\""
61
+ else
62
+ value.to_s
63
+ end
64
+ end
65
+ end.join("\n")
66
+ end
65
67
  end
66
68
  end
@@ -1,5 +1,4 @@
1
1
  require 'active_support'
2
- require File.dirname(__FILE__) + '/../../proxy'
3
2
 
4
3
  class LHS::Item < LHS::Proxy
5
4
 
@@ -1,5 +1,4 @@
1
1
  require 'active_support'
2
- require File.dirname(__FILE__) + '/../../proxy'
3
2
 
4
3
  class LHS::Item < LHS::Proxy
5
4
 
@@ -1,5 +1,4 @@
1
1
  require 'active_support'
2
- require File.dirname(__FILE__) + '/../../proxy'
3
2
 
4
3
  class LHS::Item < LHS::Proxy
5
4
 
@@ -1,5 +1,4 @@
1
1
  require 'active_support'
2
- # require File.dirname(__FILE__) + '/../../proxy'
3
2
 
4
3
  class LHS::Proxy
5
4
 
@@ -1,12 +1,16 @@
1
- require File.join(__dir__, 'proxy.rb')
2
- Dir[File.dirname(__FILE__) + '/concerns/data/*.rb'].each { |file| require file }
3
-
4
1
  # Data provides functionalities to accesses information
5
2
  class LHS::Data
3
+ autoload :Equality,
4
+ 'lhs/concerns/data/equality'
5
+ autoload :Json,
6
+ 'lhs/concerns/data/json'
7
+ autoload :ToHash,
8
+ 'lhs/concerns/data/to_hash'
9
+
6
10
  include Equality
7
11
  include Json
8
12
  include ToHash
9
- include Inspect
13
+ include LHS::Inspect
10
14
 
11
15
  delegate :instance_methods, :items_key, :limit_key, :total_key, :pagination_key, to: :class
12
16
 
@@ -1,9 +1,15 @@
1
- require File.join(__dir__, 'proxy.rb')
2
- Dir[File.dirname(__FILE__) + '/concerns/item/*.rb'].each { |file| require file }
3
-
4
1
  # An item is a concrete record.
5
2
  # It can be part of another proxy like collection.
6
3
  class LHS::Item < LHS::Proxy
4
+ autoload :Destroy,
5
+ 'lhs/concerns/item/destroy'
6
+ autoload :Save,
7
+ 'lhs/concerns/item/save'
8
+ autoload :Update,
9
+ 'lhs/concerns/item/update'
10
+ autoload :Validation,
11
+ 'lhs/concerns/item/validation'
12
+
7
13
  include Create
8
14
  include Destroy
9
15
  include Save
@@ -1,8 +1,15 @@
1
- Dir[File.dirname(__FILE__) + '/concerns/proxy/*.rb'].each { |file| require file }
2
-
3
1
  # Proxy makes different kind of data accessible
4
2
  # If href is present it also alows loading/reloading
5
3
  class LHS::Proxy
4
+ autoload :Accessors,
5
+ 'lhs/concerns/proxy/accessors'
6
+ autoload :Create,
7
+ 'lhs/concerns/proxy/create'
8
+ autoload :Errors,
9
+ 'lhs/concerns/proxy/errors'
10
+ autoload :Link,
11
+ 'lhs/concerns/proxy/link'
12
+
6
13
  include Accessors
7
14
  include Create
8
15
  include Errors
@@ -1,6 +1,42 @@
1
- Dir[File.dirname(__FILE__) + '/concerns/record/*.rb'].each { |file| require file }
2
-
3
1
  class LHS::Record
2
+ autoload :Batch,
3
+ 'lhs/concerns/record/batch'
4
+ autoload :Chainable,
5
+ 'lhs/concerns/record/chainable'
6
+ autoload :Configuration,
7
+ 'lhs/concerns/record/configuration'
8
+ autoload :Create,
9
+ 'lhs/concerns/record/create'
10
+ autoload :Destroy,
11
+ 'lhs/concerns/record/destroy'
12
+ autoload :Endpoints,
13
+ 'lhs/concerns/record/endpoints'
14
+ autoload :Equality,
15
+ 'lhs/concerns/record/equality'
16
+ autoload :Find,
17
+ 'lhs/concerns/record/find'
18
+ autoload :FindBy,
19
+ 'lhs/concerns/record/find_by'
20
+ autoload :First,
21
+ 'lhs/concerns/record/first'
22
+ autoload :Mapping,
23
+ 'lhs/concerns/record/mapping'
24
+ autoload :Model,
25
+ 'lhs/concerns/record/model'
26
+ autoload :Pagination,
27
+ 'lhs/concerns/record/pagination'
28
+ autoload :Request,
29
+ 'lhs/concerns/record/request'
30
+ autoload :Scope,
31
+ 'lhs/concerns/record/scope'
32
+
33
+ module RequestCycleCache
34
+ autoload :RequestCycleThreadRegistry,
35
+ 'lhs/concerns/record/request_cycle_cache/request_cycle_thread_registry'
36
+ autoload :Interceptor,
37
+ 'lhs/concerns/record/request_cycle_cache/interceptor'
38
+ end
39
+
4
40
  include Batch
5
41
  include Chainable
6
42
  include Configuration
@@ -11,7 +47,7 @@ class LHS::Record
11
47
  include Find
12
48
  include FindBy
13
49
  include First
14
- include Inspect
50
+ include LHS::Inspect
15
51
  include Mapping
16
52
  include Model
17
53
  include Pagination
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "11.3.3"
2
+ VERSION = "12.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.3.3
4
+ version: 12.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors
@@ -183,7 +183,9 @@ files:
183
183
  - lib/lhs.rb
184
184
  - lib/lhs/collection.rb
185
185
  - lib/lhs/complex.rb
186
+ - lib/lhs/concerns/autoload_records.rb
186
187
  - lib/lhs/concerns/collection/internal_collection.rb
188
+ - lib/lhs/concerns/configuration.rb
187
189
  - lib/lhs/concerns/data/equality.rb
188
190
  - lib/lhs/concerns/data/json.rb
189
191
  - lib/lhs/concerns/data/to_hash.rb
@@ -192,7 +194,6 @@ files:
192
194
  - lib/lhs/concerns/item/save.rb
193
195
  - lib/lhs/concerns/item/update.rb
194
196
  - lib/lhs/concerns/item/validation.rb
195
- - lib/lhs/concerns/lhs/configuration.rb
196
197
  - lib/lhs/concerns/proxy/accessors.rb
197
198
  - lib/lhs/concerns/proxy/create.rb
198
199
  - lib/lhs/concerns/proxy/errors.rb