azahara_schema 0.3.5 → 0.3.6

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
  SHA256:
3
- metadata.gz: f94ff9042c2246d38dbfabfc0b4935c0e3e187cdee2a98f23bf6f37c25b4defa
4
- data.tar.gz: 301ab4cbe1764857c16f9c26e69e607a2bac6c5be3ee335e9cd7ec63ca8c426b
3
+ metadata.gz: d41cee35775a78e8ef619042baf4a3e44e3b72488d0e6b4be145baf20d3d8175
4
+ data.tar.gz: ac919eeeb5a76024b2222f60d1afaae85b0c4d3d756c0c63564e3b6d4f8adeb2
5
5
  SHA512:
6
- metadata.gz: 9a72b9632ec5e74ff694b679fcd37dbee464dbf37300941a52b4c55312055b8bbaee54c3e2dd9f1fe2527c414f53c09dbacee7ff834528a0f99ea46b70101139
7
- data.tar.gz: 5ada7cf0f14f608d304bd7f1b6a93baa6ea7d19d76ad287486b42445251507b037ac92a26e90bb2a88ebb3878c9e509ca76f665dc20cb32233fc847a82b5bdef
6
+ metadata.gz: 9140e0d6cdfa550323172bd59932934ba988818fb8b13f9f580dc55a1e8c5db717820ee0fa2e0420be5fc4a77aee2d234c5bfc407ad836ecfc09f015a943d377
7
+ data.tar.gz: a09337cfaffcb0f6cb8fae65c6abec8313e9a59cfb1e7f33e9bbaa258aa2db95cce445219e82995922c9db5c74fc83cb9455111b1a7ed20a7a0baa4a387ab007
@@ -47,24 +47,29 @@ module AzaharaSchema
47
47
  'fa'
48
48
  end
49
49
 
50
- def attribute_human_value(attribute, entity, **options)
51
- val = attribute.value(entity)
50
+ def human_value(attribute, value, **options)
52
51
  case attribute.type
53
52
  when 'love'
54
- attribute.available_values.detect{|l, v| v == val }.try(:[], 0)
53
+ attribute.available_values.detect{|l, v| v == value }.try(:[], 0)
55
54
  when 'list'
56
- attribute.attribute_name.human_list_value(val, options)
55
+ attribute.attribute_name.human_list_value(value, options)
56
+ when 'datetime'
57
+ value ? l(value) : value
57
58
  else
58
- val
59
+ value
59
60
  end
60
61
  end
61
62
 
63
+ def attribute_human_value(attribute, entity, **options)
64
+ human_value(attribute, attribute.value(entity))
65
+ end
66
+
62
67
  def formatted_value(attribute, entity, **options)
63
68
  real_formatter(attribute).format_value(attribute, attribute_human_value(attribute, entity), formatting_options(attribute,entity).merge(options))
64
69
  end
65
70
 
66
71
  def html_formatted_value(attribute, entity, **options)
67
- format_value_html(attribute, attribute.value(entity), formatting_options(attribute,entity).merge(options))
72
+ format_value_html(attribute, attribute_human_value(attribute, entity, options), formatting_options(attribute,entity).merge(options))
68
73
  end
69
74
 
70
75
  def attribute_html_label(attribute, **options)
@@ -75,19 +80,14 @@ module AzaharaSchema
75
80
  template.content_tag('div', class: 'attribute') do
76
81
  s = ''.html_safe
77
82
  s << template.content_tag('div', attribute_html_label(attribute, options), class: 'label')
78
- s << template.content_tag('div', format_value_html(attribute, attribute.value(entity), options), class: 'value')
83
+ s << template.content_tag('div', html_formatted_value(attribute, entity, options), class: 'value')
79
84
  s
80
85
  end
81
86
  end
82
87
 
83
88
 
84
89
  def format_value(attribute, unformated_value, **options)
85
- case attribute.type
86
- when 'datetime'
87
- unformated_value ? l(unformated_value) : unformated_value
88
- else
89
- unformated_value
90
- end
90
+ unformated_value
91
91
  end
92
92
 
93
93
  def format_value_html(attribute, unformated_value, **options)
@@ -32,9 +32,13 @@ module AzaharaSchema
32
32
  AzaharaSchema::Schema.new(model, *attributes)
33
33
  end
34
34
 
35
- def self.attribute_type(model, name)
36
- col = model.columns_hash[name.to_s]
37
- col && col.type
35
+ def self.attribute_type(model, name, col=nil)
36
+ col ||= model.columns_hash[name.to_s]
37
+ if model.defined_enums[col.name]
38
+ 'list'
39
+ else
40
+ col && col.type
41
+ end
38
42
  end
39
43
 
40
44
  def self.attribute(model, name, attr_type=nil)
@@ -43,9 +47,7 @@ module AzaharaSchema
43
47
  end
44
48
 
45
49
  def self.attribute_for_column(model, col, attr_type=nil)
46
- attr_type ||= ('list' if model.defined_enums[col.name])
47
- attr_type ||= col.type
48
- attribute(model, col.name, attr_type)
50
+ attribute(model, col.name, attr_type || attribute_type(model, col.name, col) )
49
51
  end
50
52
 
51
53
  def self.enabled_filters(*filter_names)
@@ -1,3 +1,3 @@
1
1
  module AzaharaSchema
2
- VERSION = '0.3.5'
2
+ VERSION = '0.3.6'
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.3.5
4
+ version: 0.3.6
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: 2018-04-25 00:00:00.000000000 Z
11
+ date: 2018-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails