bmc 1.5.1 → 1.6.0

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: 4b45ace9fe342248cb63e77ac701779ed69c5d6bf05ff3f0b0e2b23a7b46665b
4
- data.tar.gz: 057b8aacdcd98a348b54276233b0a5ffc353580e79256c4d05c700c402779d55
3
+ metadata.gz: 761e510c5a970c4720e50d7cb25193dbd77f1d0181151fbdb9b60fa1df105826
4
+ data.tar.gz: 0d1564a511deab185e8cfc85816c4dac045ff5420a13ca64a7550fb0fb580688
5
5
  SHA512:
6
- metadata.gz: 222d61f28a75cf0699935d6272599737ac4eb9c984b5f6012c8b174f593c2eae007d91a758d1a33f67f23d2bc8b13ceb9009979e45317d758dbd184600db19ff
7
- data.tar.gz: 6f51eeb1722bf8bc536871700f4e633157e29f100f2677de68fc174cd93e30508511e2087b0aad626de55c7f77789d8d648bf3a982a90ec8a517b426ea763b46
6
+ metadata.gz: b1217842ff462ceee4909c28bea5a5f42db0ccf6addcc13f54e18fc573e1564795f13eef2c5f8043667cf2ec6fffd7f4836f1e4af32537b5e2b3dc4e2e833c50
7
+ data.tar.gz: 2d5bca38555fe9c116aa783f05943320e78a86cfecd2502adbce9e8cf4b29b682a5ce04de53359c54ae87f41927cf7eaf6bcf2a9cba08f20a7ca6f368f20aac5
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
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
+
5
10
  ## v1.5.1
6
11
  - Add options to filters and sorters
7
12
  - Fix BMC::ButtonHelper configuration
@@ -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,10 +3,10 @@ class BMC::Filter
3
3
 
4
4
  STRATEGIES = {}
5
5
 
6
- attr_reader :jar, :options
6
+ attr_reader :values, :options
7
7
 
8
- def initialize(jar, options = {})
9
- @jar = jar
8
+ def initialize(values, options = {})
9
+ @values = values.with_indifferent_access
10
10
  @options = options
11
11
  end
12
12
 
@@ -14,57 +14,32 @@ class BMC::Filter
14
14
  self.class::STRATEGIES.with_indifferent_access
15
15
  end
16
16
 
17
- def apply(query)
17
+ def call(query)
18
18
  strategies.each do |key, strategy|
19
- value = get(key)
19
+ value = values[key]
20
20
 
21
21
  next if value.blank?
22
22
 
23
- query = strategy.apply(query, value)
23
+ query = strategy.call(query, value)
24
24
  end
25
25
 
26
- return query
26
+ query
27
27
  end
28
28
 
29
- def method_missing(method, *args)
30
- if method.to_s.end_with?("=")
31
- key = method.to_s[0..-2]
32
- value = args.first
33
- action = :write
34
- else
35
- key = method.to_s
36
- action = :read
37
- end
38
-
39
- if strategies.key?(key) && action == :read
40
- get(key)
41
- elsif strategies.key?(key) && action == :write
42
- set(key, value)
29
+ def method_missing(method, ...)
30
+ if strategies.key?(method)
31
+ values[method]
43
32
  else
44
33
  super
45
34
  end
46
35
  end
47
36
 
48
37
  def respond_to_missing?(method, include_private = false)
49
- super || strategies.key?(method.to_s) || strategies.key?(method.to_s.chomp("="))
50
- end
51
-
52
- def read
53
- JSON.parse jar["filters"].to_s
54
- rescue JSON::ParserError
55
- {}
56
- end
57
-
58
- def write(filters)
59
- jar["filters"] = filters.to_json
60
- end
61
-
62
- def merge(new_filters)
63
- write read.merge(new_filters)
38
+ strategies.key?(method) || super
64
39
  end
65
40
 
66
41
  def actives_count
67
- read.count { |k, v| strategies.key?(k.to_s) && v.present? }
42
+ values.count { |k, v| strategies.key?(k) && v.present? }
68
43
  end
69
44
 
70
45
  def any?
@@ -74,14 +49,4 @@ class BMC::Filter
74
49
  def empty?
75
50
  !any?
76
51
  end
77
-
78
- private
79
-
80
- def get(key)
81
- read[key.to_s]
82
- end
83
-
84
- def set(key, value)
85
- merge(key.to_s => value)
86
- end
87
52
  end
@@ -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(
data/lib/bmc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module BMC
2
- VERSION = "1.5.1"
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.1
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-11 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