active_element 0.0.29 → 0.0.31

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: 1cb0aa53f1b0832280482cb35d23d5bbcc7ece8f7b03001f81e9d18d290cc831
4
- data.tar.gz: c1a34228e6c2529294ab30a4e9232d2ce6bef50f396951224b5740d67d992cf8
3
+ metadata.gz: 4674930632a2913f699ce77bb0ee31d83b8e11a0356a013beaa6b7d740337a0a
4
+ data.tar.gz: 3d8ed9fde6a7a6072075afb7db1c12892ca5113b5beaf14221888fd7a7f96da8
5
5
  SHA512:
6
- metadata.gz: d64eb7cc1f58b62c0e15d8b8e47029ea41073afbd058a2ce35bcee0d9e41de90ffcf32551d5d0c5a3bd2bea39d4ec7578ef99854a2530d96707b9f9bbd79e8d8
7
- data.tar.gz: bd7207c7873eda19bcba2e458e78753a95a653371f07576df7b47da2a280ad3c83fb14d85f78a1193b3ce9ba0c0cb26586a0e6ef553a2013343aa6618dc8f69f
6
+ metadata.gz: 137906e98706fe08498ebebc90fb37d2ca85ba5dc2e4ca55411cc750c515312b55473f17b0815a554744d8db6fa0f5239c3c06dbef2d22098c07258242e4a37f
7
+ data.tar.gz: 45f050797338f9c7d6ebd47f203a2fb3db6974a92a160df50606c91a43d20cab7956dbfe3673d53c5283347825cafa273f92ee4a00654f6c30cfad058960b23b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_element (0.0.29)
4
+ active_element (0.0.31)
5
5
  bootstrap (~> 5.3.0alpha3)
6
6
  kaminari (~> 1.2)
7
7
  paintbrush (~> 0.1.2)
@@ -65,7 +65,7 @@ module ActiveElement
65
65
  attr_reader :record, :controller, :type
66
66
 
67
67
  def record_path(**kwargs) # rubocop:disable Metrics/AbcSize
68
- return nil if record.nil?
68
+ return nil if record.nil? || default_record_path.nil?
69
69
 
70
70
  controller.helpers.public_send(default_record_path, *path_arguments, **kwargs)
71
71
  rescue NoMethodError
@@ -90,8 +90,16 @@ module ActiveElement
90
90
  end
91
91
 
92
92
  def default_record_path
93
- return record.controller_name.constantize.controller_path.underscore.singularize.tr('/', '_') + '_path' if record.try(:controller_name).present?
94
- "#{record_path_prefix}#{namespace_prefix}#{record_name}_path"
93
+ if record.try(:active_element_controller_name).present?
94
+ record.active_element_controller_name
95
+ .constantize.controller_path
96
+ .underscore
97
+ .singularize.tr('/', '_') + '_path'
98
+ else
99
+ "#{record_path_prefix}#{namespace_prefix}#{record_name}_path"
100
+ end
101
+ rescue NameError
102
+ nil
95
103
  end
96
104
 
97
105
  def record_path_for(name)
@@ -46,11 +46,20 @@ module ActiveElement
46
46
 
47
47
  def scalar?(field)
48
48
  return true if relation?(field)
49
- return true if %i[json jsonb].exclude?(column(field)&.type)
49
+ return true if %i[json jsonb].exclude?(field_type(field))
50
50
 
51
51
  false
52
52
  end
53
53
 
54
+ def field_type(field)
55
+ options_proc = controller.active_element.state.field_options[field]
56
+ return column(field)&.type if options_proc.nil?
57
+
58
+ field_options = FieldOptions.from_state(field, controller.active_element.state, nil, controller)
59
+ options_proc.call(field_options)
60
+ field_options.type || column(field)&.type
61
+ end
62
+
54
63
  def json_params(fields)
55
64
  # XXX: We assume all non-scalar fields are JSON fields, i.e. they must have a definition
56
65
  # defined as `config/forms/<model>/<field>.yml`. If that file does not exist, allow
@@ -53,6 +53,14 @@ module ActiveElement
53
53
  attr_reader :controller, :model
54
54
 
55
55
  def string_like_column?(key)
56
+ exact = controller.active_element.state.field_options&.find do |field, options_proc|
57
+ field_options = FieldOptions.new(key)
58
+ options_proc.call(field_options, nil, controller)
59
+ field_options.exact_match
60
+ end
61
+
62
+ return false if exact
63
+
56
64
  [:string, :text].include?(
57
65
  model.columns.find { |column| column.name.to_s == key.to_s }&.type&.to_sym
58
66
  )
@@ -1,6 +1,7 @@
1
1
  module ActiveElement
2
2
  class FieldOptions
3
- attr_accessor :type, :options, :value
3
+ attr_accessor :options, :value, :exact_match
4
+ attr_writer :type
4
5
  attr_reader :field
5
6
 
6
7
  def self.from_state(field, state, record, controller)
@@ -16,5 +17,9 @@ module ActiveElement
16
17
  @field = field
17
18
  @options = {}
18
19
  end
20
+
21
+ def type
22
+ @type || :text_field
23
+ end
19
24
  end
20
25
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveElement
4
- VERSION = '0.0.29'
4
+ VERSION = '0.0.31'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_element
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.29
4
+ version: 0.0.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Farrell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-14 00:00:00.000000000 Z
11
+ date: 2024-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bootstrap