bmc 1.5.0 → 1.6.0

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: 66917c46eb778377885fb86604c50632bc8e9d9c51a2974da48ffb4a30417567
4
- data.tar.gz: d53cf1ba56317ebe9789806270a408441690cc55d28ef87b9d0f4f3a0d7e9a64
3
+ metadata.gz: 761e510c5a970c4720e50d7cb25193dbd77f1d0181151fbdb9b60fa1df105826
4
+ data.tar.gz: 0d1564a511deab185e8cfc85816c4dac045ff5420a13ca64a7550fb0fb580688
5
5
  SHA512:
6
- metadata.gz: 6a38bde69e6cc4a9ad5187eade8fecd53f76d193d36d417a67c1eb46c1ac9283d3d94d6a3f473ac3d0ba4dc97e4bcaf60e1dcff0103c3e9c9d9673a46d705c1e
7
- data.tar.gz: 1dcc4a6a907c341dc93e36ab4f7bb81821f92523f8b86b4caa2fc854a76c334767ce49e437fcdc87c7c1bb73d30e4fd9b5eef774925375862d48b3a8f2ac1ac4
6
+ metadata.gz: b1217842ff462ceee4909c28bea5a5f42db0ccf6addcc13f54e18fc573e1564795f13eef2c5f8043667cf2ec6fffd7f4836f1e4af32537b5e2b3dc4e2e833c50
7
+ data.tar.gz: 2d5bca38555fe9c116aa783f05943320e78a86cfecd2502adbce9e8cf4b29b682a5ce04de53359c54ae87f41927cf7eaf6bcf2a9cba08f20a7ca6f368f20aac5
data/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## Next version
4
4
 
5
+ ## v1.6.0
6
+ - Filters v2
7
+ - Ruby min version is 3.3
8
+ - Rails min version is 7.1
9
+
10
+ ## v1.5.1
11
+ - Add options to filters and sorters
12
+ - Fix BMC::ButtonHelper configuration
13
+
5
14
  ## v1.5.0
6
15
  - Use Turbo instead of rails-ujs by default
7
16
 
@@ -4,14 +4,18 @@ class BMC::FiltersController < BMC::ApplicationController
4
4
  skip_after_action :verify_authorized, raise: false
5
5
  skip_after_action :verify_policy_scoped, raise: false
6
6
 
7
+ def self.parse(json)
8
+ JSON.parse(json.to_s).with_indifferent_access
9
+ rescue JSON::ParserError
10
+ {}.with_indifferent_access
11
+ end
12
+
7
13
  def create
8
- filters = BMC::Filter.new(cookies)
9
- new_filters = params.fetch(:filters, {}).permit!.to_h
10
- filters.merge new_filters
14
+ filters = self.class.parse(cookies[:filters])
15
+ filters.merge! params.fetch(:filters, {}).permit!.to_h
11
16
 
12
- # Rewrite cookie with 1 year expiry
13
17
  cookies[:filters] = {
14
- :value => cookies[:filters],
18
+ :value => JSON.dump(filters),
15
19
  :expires => 1.year.from_now,
16
20
  :path => "/",
17
21
  }
@@ -4,12 +4,12 @@ module BMC::ApiControllerConcern
4
4
  private
5
5
 
6
6
  def render_json(json = {}, options = {})
7
- json.reverse_merge!(current_user: current_user)
8
- options.reverse_merge!(current_user: current_user)
7
+ json.reverse_merge!(current_user:)
8
+ options.reverse_merge!(current_user:)
9
9
 
10
10
  json = BMC::MiniModelSerializer::Serialize.call(json, options)
11
11
 
12
- render options.merge(json: json)
12
+ render options.merge(json:)
13
13
  end
14
14
 
15
15
  def render_json_error(any_object, options = {})
@@ -1,5 +1,5 @@
1
1
  class BMC::Filter::ByDate < BMC::Filter::ByKeyValue
2
- def apply(query, value)
2
+ def call(query, value)
3
3
  value = Date.parse(value)
4
4
  super(query, value)
5
5
  end
@@ -1,5 +1,5 @@
1
1
  class BMC::Filter::ByDateBegin < BMC::Filter::ByKeyValue
2
- def apply(query, value)
2
+ def call(query, value)
3
3
  value = Date.parse(value)
4
4
  column = column_for(query)
5
5
  query.where("#{column} >= ?", value)
@@ -1,5 +1,5 @@
1
1
  class BMC::Filter::ByDateEnd < BMC::Filter::ByKeyValue
2
- def apply(query, value)
2
+ def call(query, value)
3
3
  value = Date.parse(value)
4
4
  column = column_for(query)
5
5
  query.where("#{column} <= ?", value)
@@ -7,7 +7,7 @@ class BMC::Filter::ByDateOrDatetimePeriod < BMC::Filter::ByKeyValue
7
7
  super
8
8
  end
9
9
 
10
- def apply(query, value) # rubocop:disable Metrics/MethodLength
10
+ def call(query, value) # rubocop:disable Metrics/MethodLength
11
11
  value = value.to_s
12
12
 
13
13
  if value == "today"
@@ -6,7 +6,7 @@ class BMC::Filter::ByKeyValue
6
6
  @key = key
7
7
  end
8
8
 
9
- def apply(query, value)
9
+ def call(query, value)
10
10
  return query if value == "all"
11
11
 
12
12
  value = true if value == "true"
@@ -1,5 +1,5 @@
1
1
  class BMC::Filter::ByKeyValues < BMC::Filter::ByKeyValue
2
- def apply(query, value)
2
+ def call(query, value)
3
3
  value = value.split if value.is_a?(String)
4
4
  value = value.select(&:present?)
5
5
 
@@ -3,67 +3,43 @@ class BMC::Filter
3
3
 
4
4
  STRATEGIES = {}
5
5
 
6
- attr_reader :jar
6
+ attr_reader :values, :options
7
7
 
8
- def initialize(jar)
9
- @jar = jar
8
+ def initialize(values, options = {})
9
+ @values = values.with_indifferent_access
10
+ @options = options
10
11
  end
11
12
 
12
13
  def strategies
13
14
  self.class::STRATEGIES.with_indifferent_access
14
15
  end
15
16
 
16
- def apply(query)
17
+ def call(query)
17
18
  strategies.each do |key, strategy|
18
- value = get(key)
19
+ value = values[key]
19
20
 
20
21
  next if value.blank?
21
22
 
22
- query = strategy.apply(query, value)
23
+ query = strategy.call(query, value)
23
24
  end
24
25
 
25
- return query
26
+ query
26
27
  end
27
28
 
28
- def method_missing(method, *args)
29
- if method.to_s.end_with?("=")
30
- key = method.to_s[0..-2]
31
- value = args.first
32
- action = :write
33
- else
34
- key = method.to_s
35
- action = :read
36
- end
37
-
38
- if strategies.key?(key) && action == :read
39
- get(key)
40
- elsif strategies.key?(key) && action == :write
41
- set(key, value)
29
+ def method_missing(method, ...)
30
+ if strategies.key?(method)
31
+ values[method]
42
32
  else
43
33
  super
44
34
  end
45
35
  end
46
36
 
47
37
  def respond_to_missing?(method, include_private = false)
48
- super || strategies.key?(method.to_s) || strategies.key?(method.to_s.chomp("="))
49
- end
50
-
51
- def read
52
- JSON.parse jar["filters"].to_s
53
- rescue JSON::ParserError
54
- {}
55
- end
56
-
57
- def write(filters)
58
- jar["filters"] = filters.to_json
59
- end
60
-
61
- def merge(new_filters)
62
- write read.merge(new_filters)
38
+ strategies.key?(method) || super
63
39
  end
64
40
 
65
41
  def actives_count
66
- read.count { |k, v| strategies.key?(k.to_s) && v.present? }
42
+ values.count { |k, v| strategies.key?(k) && v.present? }
67
43
  end
68
44
 
69
45
  def any?
@@ -73,14 +49,4 @@ class BMC::Filter
73
49
  def empty?
74
50
  !any?
75
51
  end
76
-
77
- private
78
-
79
- def get(key)
80
- read[key.to_s]
81
- end
82
-
83
- def set(key, value)
84
- merge(key.to_s => value)
85
- end
86
52
  end
@@ -1,6 +1,6 @@
1
1
  module BMC::ButtonHelper
2
2
  class << self
3
- attr_writer :default_size, :default_style
3
+ attr_writer :default_size, :default_style, :confirm_attribute, :method_attribute
4
4
 
5
5
  def default_size
6
6
  @default_size ||= :sm
@@ -67,8 +67,8 @@ module BMC::ButtonHelper
67
67
  public_send(helper, content, url, options.sort.to_h)
68
68
  end
69
69
 
70
- def bs_button_to(url, **options)
71
- bs_button(url, helper: :button_to, **options)
70
+ def bs_button_to(url, **)
71
+ bs_button(url, helper: :button_to, **)
72
72
  end
73
73
 
74
74
  def new_button(url = url_for(action: :new), **options)
@@ -1,14 +1,14 @@
1
1
  module BMC::FontAwesomeHelper
2
- def fa_s(id, **options)
3
- _bmc_fa_icon(id, fa_style: "fas", **options)
2
+ def fa_s(id, **)
3
+ _bmc_fa_icon(id, fa_style: "fas", **)
4
4
  end
5
5
 
6
- def fa_r(id, **options)
7
- _bmc_fa_icon(id, fa_style: "far", **options)
6
+ def fa_r(id, **)
7
+ _bmc_fa_icon(id, fa_style: "far", **)
8
8
  end
9
9
 
10
- def fa_b(id, **options)
11
- _bmc_fa_icon(id, fa_style: "fab", **options)
10
+ def fa_b(id, **)
11
+ _bmc_fa_icon(id, fa_style: "fab", **)
12
12
  end
13
13
 
14
14
  def _bmc_fa_icon(id, fa_style: nil, size: nil, spin: false, **options)
@@ -9,7 +9,7 @@ module BMC::FormHelper
9
9
  end
10
10
 
11
11
  def search_form(action: request.fullpath, placeholder: ta(:search))
12
- render "bmc/search/form", action: action, placeholder: placeholder
12
+ render "bmc/search/form", action:, placeholder:
13
13
  end
14
14
 
15
15
  def hidden_inputs_for_get_form(url, except: nil, only: nil)
@@ -9,9 +9,9 @@ module BMC::LinkHelper
9
9
  end
10
10
  end
11
11
 
12
- def icon_link_to(icon, name, options = nil, html_options = nil, &block)
12
+ def icon_link_to(icon, name, options = nil, html_options = nil, &)
13
13
  name = fa_s(icon).concat(" ").concat(name)
14
- link_to(name, options, html_options, &block)
14
+ link_to(name, options, html_options, &)
15
15
  end
16
16
 
17
17
  def web_link(text, opts = {})
@@ -84,11 +84,11 @@ module BMC::TextHelper
84
84
  label: object.t(attribute)
85
85
  )
86
86
  if default == :hide
87
- value = fma(object, attribute, value: value, helper: helper)
87
+ value = fma(object, attribute, value:, helper:)
88
88
  return if value.nil?
89
89
  end
90
90
 
91
- value = fma(object, attribute, value: value, default: default, helper: helper)
91
+ value = fma(object, attribute, value:, default:, helper:)
92
92
 
93
93
  separator = " :<br/>".html_safe if separator == :br
94
94
  klass = object.is_a?(Module) ? object : object.class
@@ -1,8 +1,8 @@
1
1
  module BMC::SetupJobConcern
2
2
  extend ActiveSupport::Concern
3
3
 
4
- def perform(*args)
5
- setup(*args)
4
+ def perform(*)
5
+ setup(*)
6
6
  call
7
7
  end
8
8
 
@@ -9,9 +9,9 @@ class BMC::MiniModelSerializer::Serializer < BMC::MiniModelSerializer::Serialize
9
9
 
10
10
  private
11
11
 
12
- def method_missing(m, *args)
12
+ def method_missing(m, *)
13
13
  if respond_to_missing?(m)
14
- object.send(m, *args)
14
+ object.send(m, *)
15
15
  else
16
16
  super
17
17
  end
@@ -18,8 +18,8 @@ class BMC::TokenGenerator
18
18
  end
19
19
 
20
20
  class << self
21
- def call(*args)
22
- new(*args).call
21
+ def call(*)
22
+ new(*).call
23
23
  end
24
24
 
25
25
  attr_writer :default_size
@@ -7,8 +7,8 @@ module BMC::ModelI18n
7
7
  end
8
8
  self.raise_on_missing_translations = false
9
9
 
10
- def t(*args)
11
- self.class.t(*args)
10
+ def t(...)
11
+ self.class.t(...)
12
12
  end
13
13
 
14
14
  def ts
@@ -3,8 +3,8 @@ class BMC::Serializers::XLSX < BMC::Serializers::Base
3
3
  headers, *data = formatted_data
4
4
 
5
5
  SpreadsheetArchitect.to_xlsx(
6
- headers: headers,
7
- data: data,
6
+ headers:,
7
+ data:,
8
8
  freeze_headers: true,
9
9
  range_styles: range_styles(data[0]),
10
10
  )
@@ -1,13 +1,11 @@
1
1
  class BMC::SMS::Strategies::Amazon
2
2
  attr_reader :region, :access_key_id, :secret_access_key
3
3
 
4
- # rubocop:disable Layout/LineLength
5
4
  def initialize(region: nil, access_key_id: nil, secret_access_key: nil)
6
5
  @region = region || ENV["SNS_REGION"] || ENV["AWS_REGION"]
7
6
  @access_key_id = access_key_id || ENV["SNS_ACCESS_KEY_ID"] || ENV["AWS_ACCESS_KEY_ID"]
8
7
  @secret_access_key = secret_access_key || ENV["SNS_SECRET_ACCESS_KEY"] || ENV["AWS_SECRET_ACCESS_KEY"]
9
8
  end
10
- # rubocop:enable Layout/LineLength
11
9
 
12
10
  def client
13
11
  @client ||= Aws::SNS::Client.new(
@@ -1,15 +1,16 @@
1
1
  class BMC::Sorter
2
2
  include BMC::SortingHelper
3
3
 
4
- attr_reader :collection, :sort_param, :column, :direction
4
+ attr_reader :collection, :sort_param, :options, :column, :direction
5
5
 
6
6
  def self.call(...)
7
7
  new(...).call
8
8
  end
9
9
 
10
- def initialize(collection, sort_param = nil)
11
- @collection = collection
12
- @sort_param = sort_param
10
+ def initialize(collection, sort_param, options = {})
11
+ @collection = collection
12
+ @sort_param = sort_param
13
+ @options = options
13
14
  @column, @direction = sortable_column_order(sort_param.to_s)
14
15
  end
15
16
 
data/lib/bmc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module BMC
2
- VERSION = "1.5.0"
2
+ VERSION = "1.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bmc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benoit MARTIN-CHAVE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-06 00:00:00.000000000 Z
11
+ date: 2024-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails-i18n
@@ -230,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
230
  - !ruby/object:Gem::Version
231
231
  version: '0'
232
232
  requirements: []
233
- rubygems_version: 3.5.6
233
+ rubygems_version: 3.5.11
234
234
  signing_key:
235
235
  specification_version: 4
236
236
  summary: BMC