azahara_schema 0.1.3 → 0.1.5

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: d672ff9453d94ce1d4926ca08e78bd3df9298fb3
4
- data.tar.gz: b3101131a1b1d578edeaac3444af869212afb5e3
3
+ metadata.gz: 8f7f9fca28c48e48db64c1fff3f830700b6e3c52
4
+ data.tar.gz: e0fbdebd3f9656fbb739684d4d37da76a8825d84
5
5
  SHA512:
6
- metadata.gz: 1b3a6f4232a219e888beaf3f36b5b6e243ec286e4af28ce850afa6d2ad93a4468ed4e4cbbff562bce546544a8a6da6bf95513eb8a71491acd894681f504ff9b7
7
- data.tar.gz: a99067d5f78de03f6672b2c8c33aff2695aa4ab6828f4ce85479f7fa7bd51505b29c271c5cd4dc0fea2efbb5b2f81895e43ed227bfef05ed2f9e4693a420a242
6
+ metadata.gz: a6804635de61f3adf1ebefec3476052195dd507231083906f163abe8e0dd80a6e41dc2518216f561de9a132117bb759c25b481616d0ddac4ea43141d9b8666cf
7
+ data.tar.gz: d9d8df57a99ce9a9cae33299015448153f688dd68a5d023847c1c33e14b55f72143c23ff486d8f2841f1999fb4a187b7caf3424e10a81375921007645416a376
@@ -7,7 +7,7 @@ module AzaharaSchema
7
7
 
8
8
  def filter_field(schema, filter)
9
9
  case filter.format.format_name
10
- when 'list'
10
+ when 'list', 'love'
11
11
  select :f, filter.filter_name, options_for_select( list_values_for_select(filter), schema.value_for(filter.filter_name) ), {include_blank: true}, class: 'form-control value-field'
12
12
  else
13
13
  text_field :f, filter.filter_name, value: schema.value_for(filter.filter_name), class: 'form-control value-field'
@@ -17,8 +17,12 @@ module AzaharaSchema
17
17
  # translates values to list_values
18
18
  # TODO: not needed to do it for every value - for example districts are not translatable
19
19
  def list_values_for_select(attribute)
20
- attribute.available_values.collect do |l, val|
21
- [t(l, scope: [:activerecord, :attributes, attribute.model.model_name.i18n_key, attribute.name.to_s.pluralize], default: l.to_s), val]
20
+ if attribute.format.format_name == 'list'
21
+ attribute.available_values.collect do |l, val|
22
+ [t(l, scope: [:activerecord, :attributes, attribute.model.model_name.i18n_key, attribute.name.to_s.pluralize], default: l.to_s), val]
23
+ end
24
+ else
25
+ attribute.available_values
22
26
  end
23
27
  end
24
28
 
@@ -36,6 +36,7 @@ module AzaharaSchema
36
36
  name
37
37
  end
38
38
 
39
+ # Path in json structure
39
40
  def path
40
41
  name
41
42
  end
@@ -83,6 +83,10 @@ module AzaharaSchema
83
83
  end
84
84
  end
85
85
 
86
+ class LoveFormat < ListFormat
87
+ add 'love'
88
+ end
89
+
86
90
  class DateFormat < Base
87
91
  add 'date'
88
92
  end
@@ -156,7 +156,10 @@ module AzaharaSchema
156
156
 
157
157
  def available_associations
158
158
  @available_associations ||= model.reflect_on_all_associations.select do |association|
159
- association.klass != model && !association_path.include?( association.name.to_s.singularize.to_sym ) && !association_path.include?( association.name.to_s.pluralize.to_sym )
159
+ association.klass != model &&
160
+ !association.options[:polymorphic] &&
161
+ !association_path.include?( association.name.to_s.singularize.to_sym ) &&
162
+ !association_path.include?( association.name.to_s.pluralize.to_sym )
160
163
  end.collect do |association|
161
164
  AzaharaSchema::Schema.schema_for(association.klass, parent_schema: self, association: association)
162
165
  end
@@ -203,7 +206,9 @@ module AzaharaSchema
203
206
  end
204
207
 
205
208
  def as_json(options={})
206
- entities.as_json(build_json_options!(options))
209
+ res_ary = entities.as_json(build_json_options!(options))
210
+ columns.each{|col| res_ary.each{|attr_hash| attr_hash[col.name] = col.available_values.detect{|l, v| v == attr_hash[col.name] }.try(:[], 0) } if col.type == 'love' }
211
+ res_ary
207
212
  end
208
213
 
209
214
 
@@ -1,3 +1,3 @@
1
1
  module AzaharaSchema
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.5'
3
3
  end
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.3
4
+ version: 0.1.5
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-10-24 00:00:00.000000000 Z
11
+ date: 2017-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails