azahara_schema 0.1.0 → 0.1.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fdc281f1678559822f32f72ae8dc63a8ae3cb0c
|
4
|
+
data.tar.gz: 94a238cae3c82df5573c651a81d9b5d0ea3e78f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b5c33963f165442367dcb014f17b5d287094cda153da630815eae239bcf6fc166f40591339be34932d3dc4fba02154a876ed672ab9d78ba369f08f4727fda33
|
7
|
+
data.tar.gz: c3bb384bcde4c9a27881c86b39ca42ccc120b2f3d8b80b3470754e4f8bbaea8f82f01d8ddcd22b9790a1a54c79bea3cd651ba09b6b1b57e4667bbdf421afa838
|
@@ -50,6 +50,14 @@ module AzaharaSchema
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
def add_preload(scope)
|
54
|
+
if attribute.is_a?(AzaharaSchema::AssociationAttribute)
|
55
|
+
scope.preload(association.name => attribute.association.name)
|
56
|
+
else
|
57
|
+
scope.preload(association.name)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
53
61
|
def add_statement(scope, operator, values)
|
54
62
|
super(add_join(scope), operator, values)
|
55
63
|
end
|
@@ -58,5 +66,12 @@ module AzaharaSchema
|
|
58
66
|
super(add_join(scope), order)
|
59
67
|
end
|
60
68
|
|
69
|
+
def build_json_options!(options)
|
70
|
+
options[:include] ||= {}
|
71
|
+
options[:include][association.name.to_sym] ||= {}
|
72
|
+
attribute.build_json_options!(options[:include][association.name.to_sym])
|
73
|
+
options
|
74
|
+
end
|
75
|
+
|
61
76
|
end
|
62
77
|
end
|
@@ -52,6 +52,10 @@ module AzaharaSchema
|
|
52
52
|
record.public_send(name)
|
53
53
|
end
|
54
54
|
|
55
|
+
def add_preload(scope)
|
56
|
+
scope
|
57
|
+
end
|
58
|
+
|
55
59
|
def add_statement(scope, operator, values)
|
56
60
|
case operator
|
57
61
|
when '='
|
@@ -69,5 +73,9 @@ module AzaharaSchema
|
|
69
73
|
scope.order( arel_sort_field.public_send(order) )
|
70
74
|
end
|
71
75
|
|
76
|
+
def build_json_options!(options)
|
77
|
+
options
|
78
|
+
end
|
79
|
+
|
72
80
|
end
|
73
81
|
end
|
@@ -2,12 +2,16 @@ module AzaharaSchema
|
|
2
2
|
class Schema
|
3
3
|
|
4
4
|
def self.schema_for(klass, *attributes)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
klasses = [klass]
|
6
|
+
while klass != klass.base_class
|
7
|
+
klass = klass.superclass
|
8
|
+
klasses << klass
|
9
|
+
end
|
10
|
+
klasses.each do |kls|
|
11
|
+
schema_klass = "#{kls.name}Schema".safe_constantize
|
12
|
+
return schema_klass.new(*attributes) if schema_klass
|
10
13
|
end
|
14
|
+
AzaharaSchema::Schema.new(klass, *attributes)
|
11
15
|
end
|
12
16
|
|
13
17
|
def self.enabled_filters(*filter_names)
|
@@ -36,7 +40,7 @@ module AzaharaSchema
|
|
36
40
|
end
|
37
41
|
|
38
42
|
def columns
|
39
|
-
@columns ||=
|
43
|
+
@columns ||= available_attributes_hash.slice(*column_names).values
|
40
44
|
end
|
41
45
|
|
42
46
|
def filters
|
@@ -103,6 +107,10 @@ module AzaharaSchema
|
|
103
107
|
@available_attributes
|
104
108
|
end
|
105
109
|
|
110
|
+
def available_attributes_hash
|
111
|
+
available_attributes.inject({}){|obj, aa| obj[aa.name] = aa; obj }
|
112
|
+
end
|
113
|
+
|
106
114
|
def available_columns
|
107
115
|
@available_columns ||= available_attributes.select{|att| att.column? }
|
108
116
|
end
|
@@ -148,6 +156,9 @@ module AzaharaSchema
|
|
148
156
|
|
149
157
|
def entities
|
150
158
|
scope = model.respond_to?(:visible) ? model.visible : model.all
|
159
|
+
columns.each do |col|
|
160
|
+
scope = col.add_preload(scope)
|
161
|
+
end
|
151
162
|
filters.each do |name, attrs|
|
152
163
|
scope = available_filters[name].add_statement(scope, attrs[:o], attrs[:v])
|
153
164
|
end
|
@@ -158,6 +169,15 @@ module AzaharaSchema
|
|
158
169
|
scope
|
159
170
|
end
|
160
171
|
|
172
|
+
def build_json_options!(options={})
|
173
|
+
columns.each{|col| col.build_json_options!(options) }
|
174
|
+
options
|
175
|
+
end
|
176
|
+
|
177
|
+
def as_json(options={})
|
178
|
+
entities.as_json(build_json_options!(options))
|
179
|
+
end
|
180
|
+
|
161
181
|
|
162
182
|
#serialization
|
163
183
|
def from_params(params)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: azahara_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ondřej Ezr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.
|
98
|
+
rubygems_version: 2.6.13
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: Gem to support developement of rails application with schema over an entity
|