lhs 11.3.3 → 12.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhs.rb +41 -32
- data/lib/lhs/collection.rb +1 -3
- data/lib/lhs/concerns/autoload_records.rb +36 -0
- data/lib/lhs/concerns/collection/internal_collection.rb +0 -1
- data/lib/lhs/concerns/{lhs/configuration.rb → configuration.rb} +0 -0
- data/lib/lhs/concerns/inspect.rb +53 -51
- data/lib/lhs/concerns/item/destroy.rb +0 -1
- data/lib/lhs/concerns/item/save.rb +0 -1
- data/lib/lhs/concerns/item/update.rb +0 -1
- data/lib/lhs/concerns/proxy/link.rb +0 -1
- data/lib/lhs/data.rb +8 -4
- data/lib/lhs/item.rb +9 -3
- data/lib/lhs/proxy.rb +9 -2
- data/lib/lhs/record.rb +39 -3
- data/lib/lhs/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fc72f0094042042734fdecaec1df8b9c07194a2
|
4
|
+
data.tar.gz: 33bc6824ba84ac62a79a7c2cc324f61681789847
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
#
|
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
|
-
|
39
|
-
end
|
48
|
+
require 'lhs/railtie' if defined?(Rails)
|
40
49
|
end
|
data/lib/lhs/collection.rb
CHANGED
@@ -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
|
File without changes
|
data/lib/lhs/concerns/inspect.rb
CHANGED
@@ -1,66 +1,68 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
|
3
|
-
module
|
4
|
-
|
3
|
+
module LHS
|
4
|
+
module Inspect
|
5
|
+
extend ActiveSupport::Concern
|
5
6
|
|
6
|
-
|
7
|
-
[
|
7
|
+
def inspect
|
8
8
|
[
|
9
9
|
[
|
10
10
|
[
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
23
|
+
private
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def _inspect_id
|
26
|
+
_root.href || (_root.item? ? _root.id : nil) || object_id
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
data/lib/lhs/data.rb
CHANGED
@@ -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
|
|
data/lib/lhs/item.rb
CHANGED
@@ -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
|
data/lib/lhs/proxy.rb
CHANGED
@@ -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
|
data/lib/lhs/record.rb
CHANGED
@@ -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
|
data/lib/lhs/version.rb
CHANGED
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:
|
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
|