azahara_schema 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/azahara_schema/aggregation_attribute.rb +24 -0
- data/lib/azahara_schema/attribute.rb +4 -0
- data/lib/azahara_schema/engine.rb +1 -0
- data/lib/azahara_schema/field_format.rb +8 -0
- data/lib/azahara_schema/schema.rb +16 -4
- data/lib/azahara_schema/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fce09b13b68a342872733bbcc7fe3b18907a62af
|
4
|
+
data.tar.gz: 67f2b89be27832d8881b9f19409991bd63801331
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e38cac517db7b62ce49c2c02d94a886dc970d4765743cee6288901b06e007a81aad43feaa9a7b4307a41ae8bd16e8dbeb974515475807d10c1bf21b897b7561
|
7
|
+
data.tar.gz: 49677a40199bcbf7e699351ca131225348d48fe82a96a503ccbd0045c23f72362f55de3f4d35b792687fd55f17059f4f731accbeba1abd1356ac3ca8603c074c
|
data/README.md
CHANGED
@@ -28,6 +28,9 @@ $ gem install azahara_schema
|
|
28
28
|
```
|
29
29
|
|
30
30
|
## Usage
|
31
|
+
|
32
|
+
Detailed developers documentation can be found at [Documentation](https://git.servis.justice.cz/libraries/azahara_schema/wikis/home).
|
33
|
+
|
31
34
|
Default usage is only for Rails.
|
32
35
|
|
33
36
|
You basically need just this:
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Author:: Ondřej Ezr (mailto:oezr@msp.justice.cz)
|
2
|
+
# Copyright:: Copyright (c) 2017 Ministry of Justice
|
3
|
+
# License:: Distributes under license Open Source Licence pro Veřejnou Správu a Neziskový Sektor v.1
|
4
|
+
|
5
|
+
module AzaharaSchema
|
6
|
+
class AggregationAttribute < Attribute
|
7
|
+
|
8
|
+
attr_reader :attribute
|
9
|
+
|
10
|
+
def initialize(model, attribute)
|
11
|
+
@attribute = attribute
|
12
|
+
super(model, 'sum:'+attribute.name, attribute.type)
|
13
|
+
end
|
14
|
+
|
15
|
+
def arel_field
|
16
|
+
attribute.arel_field.sum
|
17
|
+
end
|
18
|
+
|
19
|
+
def value(parent)
|
20
|
+
attribute.attribute.add_join( parent.send(attribute.association.name) ).sum(attribute.arel_field).to_f
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'azahara_schema/field_format'
|
2
2
|
require 'azahara_schema/attribute'
|
3
3
|
require 'azahara_schema/association_attribute'
|
4
|
+
require 'azahara_schema/aggregation_attribute'
|
4
5
|
require 'azahara_schema/attribute_name'
|
5
6
|
require 'azahara_schema/outputs'
|
6
7
|
require 'azahara_schema/output'
|
@@ -47,12 +47,20 @@ module AzaharaSchema
|
|
47
47
|
def available_operators
|
48
48
|
['=']
|
49
49
|
end
|
50
|
+
|
51
|
+
def aggregable?
|
52
|
+
false
|
53
|
+
end
|
50
54
|
end
|
51
55
|
|
52
56
|
class NumberFormat < Base
|
53
57
|
def available_operators
|
54
58
|
super.concat(['>=','<=', '><'])
|
55
59
|
end
|
60
|
+
|
61
|
+
def aggregable?
|
62
|
+
true
|
63
|
+
end
|
56
64
|
end
|
57
65
|
|
58
66
|
class IntegerFormat < NumberFormat
|
@@ -177,7 +177,10 @@ module AzaharaSchema
|
|
177
177
|
end
|
178
178
|
available_associations.each do |asoc_schema|
|
179
179
|
asoc_schema.available_attributes.each do |asoc_attribute|
|
180
|
-
|
180
|
+
next if asoc_attribute.is_a?(AggregationAttribute)
|
181
|
+
added_attribute = AssociationAttribute.new(model, asoc_schema, asoc_attribute)
|
182
|
+
@available_attributes << added_attribute
|
183
|
+
@available_attributes << AggregationAttribute.new(model, added_attribute) if asoc_attribute.aggregable?
|
181
184
|
end
|
182
185
|
end
|
183
186
|
end
|
@@ -206,10 +209,19 @@ module AzaharaSchema
|
|
206
209
|
options
|
207
210
|
end
|
208
211
|
|
212
|
+
def entity_as_json(entity, options=nil)
|
213
|
+
attr_hash = entity.as_json(options)
|
214
|
+
# TODO serializable_add_includes(options) do |association, records, opts|
|
215
|
+
columns.each do |col|
|
216
|
+
attr_hash[col.name] = col.available_values.detect{|l, v| v == attr_hash[col.name] }.try(:[], 0) if col.type == 'love'
|
217
|
+
attr_hash[col.name] = col.value(entity) if col.is_a?(AzaharaSchema::AggregationAttribute)
|
218
|
+
end
|
219
|
+
attr_hash
|
220
|
+
end
|
221
|
+
|
209
222
|
def as_json(options={})
|
210
|
-
|
211
|
-
|
212
|
-
res_ary
|
223
|
+
build_json_options!(options)
|
224
|
+
entities.collect{|entity| entity_as_json(entity, options) }
|
213
225
|
end
|
214
226
|
|
215
227
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ondřej Ezr
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- config/locales/cs.yml
|
66
66
|
- config/routes.rb
|
67
67
|
- lib/azahara_schema.rb
|
68
|
+
- lib/azahara_schema/aggregation_attribute.rb
|
68
69
|
- lib/azahara_schema/association_attribute.rb
|
69
70
|
- lib/azahara_schema/attribute.rb
|
70
71
|
- lib/azahara_schema/attribute_name.rb
|