hellobase 0.1.12 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97553f4ffdcf70e04c9458401cda7c8fa90214289446ed80a9a470b0f33824d5
4
- data.tar.gz: 895a9128b0a720b6153b3b1b8e180c909f7f6c591b2bb227d7a0b4e31fb510ba
3
+ metadata.gz: fb6c04b21300bc5a358e8b7b6ae7c423ee10a0f0a258e974874c3b77da60d0d3
4
+ data.tar.gz: 8cf2413675ca561f4848a26e40827eb6ea7022be119ce277c2b661f441b868d6
5
5
  SHA512:
6
- metadata.gz: f6cc31a56055ec57f79230a080ee53c85ac10392c0e662fb730e86f28e3f453eb14a93da96e7f999b94f2ba4abd7690bf666c6644782b1c8d380354c6f9c6309
7
- data.tar.gz: c342ae01d51cbba476e1cffd0a043dad49db5463dcc47119588115b211a40c1987b98369ee0acb269d2e266b21ca9a33b0d25893687163c2e243b6794937cf4e
6
+ metadata.gz: 2986eccc233337b836f9c88930d141b22cbc1d7013d3f57bef9a1fa6f5b804c35b6692c22421f1fe801a9ee834ef4ac4ceaa52c66befa251112cc9eaa7775d99
7
+ data.tar.gz: df1482326fcdd1bb4c801fd3a137c846f778854c3167a8b8b9c7661b26943d08d25642caa5e3c28981e543366877fafd85c8f3b7200650d8559e0996c9e62247
@@ -1,6 +1,7 @@
1
1
  require 'bigdecimal'
2
2
  require 'date'
3
3
  require 'active_support/core_ext/date'
4
+ require 'active_support/core_ext/numeric'
4
5
  require 'active_support/core_ext/time'
5
6
  require 'active_support/duration'
6
7
  require 'tod'
@@ -20,7 +20,7 @@ Time.singleton_class.prepend(
20
20
 
21
21
  def new(*args)
22
22
  # only allow ActiveSupport::TimeZone to use Time.new
23
- unless caller_locations(1, 1)[0].path.end_with? 'active_support/values/time_zone.rb'
23
+ unless caller_locations.any? {|loc| loc.path.end_with? '/active_support/values/time_zone.rb' }
24
24
  raise Hellobase::Error.new(:datetime_new, nil)
25
25
  end
26
26
 
@@ -7,54 +7,64 @@ require 'active_admin/inputs'
7
7
  class DatepickerWithTimeInput
8
8
  include ::Formtastic::Inputs::Base
9
9
 
10
- def self.virtual_attributes(attr)
11
- [:"_dpwt_#{attr}_d", :"_dpwt_#{attr}_t"]
10
+ def self.virtual_attributes(base)
11
+ [:"_dpwt_#{base}_d", :"_dpwt_#{base}_h", :"_dpwt_#{base}_m"]
12
12
  end
13
13
 
14
- def self.define_virtual_attributes(klass, attr)
15
- return if klass.respond_to? :_dpwt_defined
14
+ def self.define_virtual_attributes(klass, base)
15
+ attrs = virtual_attributes(base)
16
+ ivars = attrs.map {|a| :"@#{a}" }
17
+ method = :"_dpwt_set_#{base}"
16
18
 
17
- klass.class_eval <<-RUBY
18
- def self._dpwt_defined; end
19
-
20
- def _dpwt_#{attr}_d
21
- self.#{attr}&.strftime('%Y-%m-%d')
19
+ klass.class_eval do
20
+ define_method attrs[0] do
21
+ send(base)&.strftime('%Y-%m-%d')
22
22
  end
23
23
 
24
- def _dpwt_#{attr}_t
25
- self.#{attr}&.strftime('%R')
24
+ define_method attrs[1] do
25
+ send(base)&.strftime('%H')
26
26
  end
27
27
 
28
- def _dpwt_#{attr}_d=(val)
29
- @_dpwt_#{attr}_d = val
30
- _dpwt_set_#{attr}
31
-
32
- val
28
+ define_method attrs[2] do
29
+ send(base)&.strftime('%M')
33
30
  end
34
31
 
35
- def _dpwt_#{attr}_t=(val)
36
- @_dpwt_#{attr}_t = val
37
- _dpwt_set_#{attr}
32
+ attrs.each_with_index do |a, i|
33
+ define_method :"#{a}=" do |val|
34
+ instance_variable_set ivars[i], val
35
+ send(method)
38
36
 
39
- val
37
+ val
38
+ end
40
39
  end
41
40
 
42
- private
43
-
44
- def _dpwt_set_#{attr}
45
- self.#{attr} = @_dpwt_#{attr}_d.blank? || @_dpwt_#{attr}_t.blank? ? nil : [@_dpwt_#{attr}_d, @_dpwt_#{attr}_t].join(' ')
41
+ define_method method do
42
+ send :"#{base}=",
43
+ ivars.any? {|v| instance_variable_get(v).blank? } ?
44
+ nil :
45
+ [
46
+ instance_variable_get(ivars[0]),
47
+ [
48
+ instance_variable_get(ivars[1]),
49
+ instance_variable_get(ivars[2])
50
+ ].join(':')
51
+ ].join(' ')
46
52
  end
47
- RUBY
53
+
54
+ private method
55
+ end
48
56
  end
49
57
 
50
58
  def to_html
51
59
  datepicker_html = ActiveAdmin::Inputs::DatepickerInput.new(builder, template, object, object_name, :"_dpwt_#{method}_d", datepicker_options).to_html
52
- time_select_html = Formtastic::Inputs::SelectInput.new(builder, template, object, object_name, :"_dpwt_#{method}_t", time_select_options).to_html
60
+ hour_select_html = Formtastic::Inputs::SelectInput.new(builder, template, object, object_name, :"_dpwt_#{method}_h", hour_select_options).to_html
61
+ minute_select_html = Formtastic::Inputs::SelectInput.new(builder, template, object, object_name, :"_dpwt_#{method}_m", minute_select_options).to_html
53
62
  zone_display_html = options[:time_zone] ? template.content_tag(:span, options[:time_zone]) : nil
54
63
 
55
64
  wrapper_contents = [
56
65
  replace_li_tag(datepicker_html),
57
- replace_li_tag(time_select_html),
66
+ replace_li_tag(hour_select_html),
67
+ replace_li_tag(minute_select_html),
58
68
  zone_display_html,
59
69
  error_html,
60
70
  hint_html,
@@ -71,11 +81,18 @@ class DatepickerWithTimeInput
71
81
  }.merge(options[:datepicker_options] || {})
72
82
  end
73
83
 
74
- def time_select_options
84
+ def hour_select_options
85
+ {
86
+ label: false,
87
+ collection: (0..23).map {|i| '%02i' % i },
88
+ }.merge(options[:hour_select_options] || {})
89
+ end
90
+
91
+ def minute_select_options
75
92
  {
76
93
  label: false,
77
- collection: (0..23).map {|h| (0..59).select {|m| m % 5 == 0 }.map {|m| ['%02i' % h, '%02i' % m].join(':') } }.flatten,
78
- }.merge(options[:time_select_options] || {})
94
+ collection: (0..59).map {|i| '%02i' % i },
95
+ }.merge(options[:minute_select_options] || {})
79
96
  end
80
97
 
81
98
  # formtastic inputs generate <li> with no way to override
@@ -1,3 +1,3 @@
1
1
  module Hellobase
2
- VERSION = '0.1.12'
2
+ VERSION = '0.1.17'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hellobase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Wang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-19 00:00:00.000000000 Z
11
+ date: 2021-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin
@@ -99,9 +99,6 @@ dependencies:
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '5.13'
104
- - - "<"
105
102
  - !ruby/object:Gem::Version
106
103
  version: '5.14'
107
104
  type: :development
@@ -109,9 +106,6 @@ dependencies:
109
106
  version_requirements: !ruby/object:Gem::Requirement
110
107
  requirements:
111
108
  - - "~>"
112
- - !ruby/object:Gem::Version
113
- version: '5.13'
114
- - - "<"
115
109
  - !ruby/object:Gem::Version
116
110
  version: '5.14'
117
111
  - !ruby/object:Gem::Dependency
@@ -184,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
178
  - !ruby/object:Gem::Version
185
179
  version: '0'
186
180
  requirements: []
187
- rubygems_version: 3.1.4
181
+ rubygems_version: 3.0.8
188
182
  signing_key:
189
183
  specification_version: 4
190
184
  summary: Ruby runtime environment for Hellobase