From 4ff44aed4ce1797043df3a52da7e244bfe00f46d Mon Sep 17 00:00:00 2001 From: viehlieb Date: Fri, 6 Jan 2023 16:27:41 +0100 Subject: [PATCH] mv lib to app/lib due to upgrade --- {lib => app/lib}/api/errors.rb | 0 {lib => app/lib}/apple_bar.rb | 16 +++++----- {lib => app/lib}/articles_csv.rb | 4 +-- {lib => app/lib}/bank_account_connector.rb | 30 ++++--------------- .../lib}/bank_account_connector_external.rb | 0 .../lib}/bank_account_information_importer.rb | 0 .../lib}/bank_transaction_reference.rb | 4 +-- {lib => app/lib}/bank_transactions_csv.rb | 0 .../lib}/date_time_attribute_validate.rb | 24 ++++++++++++--- .../lib}/financial_transactions_csv.rb | 0 .../lib}/foodsoft/expansion_variables.rb | 4 +-- {lib => app/lib}/foodsoft_config.rb | 5 ++-- {lib => app/lib}/foodsoft_date_util.rb | 11 +++++-- {lib => app/lib}/foodsoft_file.rb | 0 {lib => app/lib}/foodsoft_mail_receiver.rb | 22 +++++++------- {lib => app/lib}/invoices_csv.rb | 2 +- {lib => app/lib}/order_csv.rb | 0 {lib => app/lib}/order_pdf.rb | 8 ++--- {lib => app/lib}/order_txt.rb | 6 ++-- {lib => app/lib}/ordergroups_csv.rb | 6 ++-- {lib => app/lib}/render_csv.rb | 0 {lib => app/lib}/render_pdf.rb | 7 +++-- {lib => app/lib}/spreadsheet_file.rb | 0 .../templates/haml/scaffold/_form.html.haml | 0 {lib => app/lib}/token_verifier.rb | 4 --- {lib => app/lib}/users_csv.rb | 0 26 files changed, 75 insertions(+), 78 deletions(-) rename {lib => app/lib}/api/errors.rb (100%) rename {lib => app/lib}/apple_bar.rb (75%) rename {lib => app/lib}/articles_csv.rb (90%) rename {lib => app/lib}/bank_account_connector.rb (90%) rename {lib => app/lib}/bank_account_connector_external.rb (100%) rename {lib => app/lib}/bank_account_information_importer.rb (100%) rename {lib => app/lib}/bank_transaction_reference.rb (85%) rename {lib => app/lib}/bank_transactions_csv.rb (100%) rename {lib => app/lib}/date_time_attribute_validate.rb (82%) rename {lib => app/lib}/financial_transactions_csv.rb (100%) rename {lib => app/lib}/foodsoft/expansion_variables.rb (96%) rename {lib => app/lib}/foodsoft_config.rb (99%) rename {lib => app/lib}/foodsoft_date_util.rb (84%) rename {lib => app/lib}/foodsoft_file.rb (100%) rename {lib => app/lib}/foodsoft_mail_receiver.rb (73%) rename {lib => app/lib}/invoices_csv.rb (98%) rename {lib => app/lib}/order_csv.rb (100%) rename {lib => app/lib}/order_pdf.rb (96%) rename {lib => app/lib}/order_txt.rb (81%) rename {lib => app/lib}/ordergroups_csv.rb (88%) rename {lib => app/lib}/render_csv.rb (100%) rename {lib => app/lib}/render_pdf.rb (98%) rename {lib => app/lib}/spreadsheet_file.rb (100%) rename {lib => app/lib}/templates/haml/scaffold/_form.html.haml (100%) rename {lib => app/lib}/token_verifier.rb (97%) rename {lib => app/lib}/users_csv.rb (100%) diff --git a/lib/api/errors.rb b/app/lib/api/errors.rb similarity index 100% rename from lib/api/errors.rb rename to app/lib/api/errors.rb diff --git a/lib/apple_bar.rb b/app/lib/apple_bar.rb similarity index 75% rename from lib/apple_bar.rb rename to app/lib/apple_bar.rb index a2176ea3..236417c6 100644 --- a/lib/apple_bar.rb +++ b/app/lib/apple_bar.rb @@ -14,23 +14,23 @@ class AppleBar def group_bar_state if apples >= 100 'success' + elsif FoodsoftConfig[:stop_ordering_under].present? && + (apples >= FoodsoftConfig[:stop_ordering_under]) + 'warning' else - if FoodsoftConfig[:stop_ordering_under].present? and - apples >= FoodsoftConfig[:stop_ordering_under] - 'warning' - else - 'danger' - end + 'danger' end end # Use apples as percentage, but show at least 10 percent def group_bar_width - @ordergroup.apples < 2 ? 2 : @ordergroup.apples + [@ordergroup.apples, 2].max end def mean_order_amount_per_job - (1 / @global_avg).round rescue 0 + (1 / @global_avg).round + rescue + 0 end def apples diff --git a/lib/articles_csv.rb b/app/lib/articles_csv.rb similarity index 90% rename from lib/articles_csv.rb rename to app/lib/articles_csv.rb index 910de9be..9e6b4f40 100644 --- a/lib/articles_csv.rb +++ b/app/lib/articles_csv.rb @@ -16,7 +16,7 @@ class ArticlesCsv < RenderCSV Article.human_attribute_name(:unit_quantity), '', '', - Article.human_attribute_name(:article_category), + Article.human_attribute_name(:article_category) ] end @@ -36,7 +36,7 @@ class ArticlesCsv < RenderCSV o.unit_quantity, '', '', - o.article_category.try(:name), + o.article_category.try(:name) ] end end diff --git a/lib/bank_account_connector.rb b/app/lib/bank_account_connector.rb similarity index 90% rename from lib/bank_account_connector.rb rename to app/lib/bank_account_connector.rb index 93e7cc7c..b728ebb9 100644 --- a/lib/bank_account_connector.rb +++ b/app/lib/bank_account_connector.rb @@ -8,9 +8,7 @@ class BankAccountConnector nil end - def text - @text - end + attr_reader :text end class TextField @@ -24,13 +22,7 @@ class BankAccountConnector nil end - def name - @name - end - - def value - @value - end + attr_reader :name, :value def label @label || @name.to_s @@ -73,17 +65,7 @@ class BankAccountConnector @bank_account.iban end - def auto_submit - @auto_submit - end - - def controls - @controls - end - - def count - @count - end + attr_reader :auto_submit, :controls, :count def text(data) @controls += [TextItem.new(data)] @@ -142,11 +124,9 @@ class BankAccountConnector @bank_account.save! end - def load(data) - end + def load(data); end - def dump - end + def dump; end def t(key, args = {}) return t(".fields.#{key}") unless key.is_a? String diff --git a/lib/bank_account_connector_external.rb b/app/lib/bank_account_connector_external.rb similarity index 100% rename from lib/bank_account_connector_external.rb rename to app/lib/bank_account_connector_external.rb diff --git a/lib/bank_account_information_importer.rb b/app/lib/bank_account_information_importer.rb similarity index 100% rename from lib/bank_account_information_importer.rb rename to app/lib/bank_account_information_importer.rb diff --git a/lib/bank_transaction_reference.rb b/app/lib/bank_transaction_reference.rb similarity index 85% rename from lib/bank_transaction_reference.rb rename to app/lib/bank_transaction_reference.rb index d033c544..22b9f181 100644 --- a/lib/bank_transaction_reference.rb +++ b/app/lib/bank_transaction_reference.rb @@ -1,7 +1,7 @@ class BankTransactionReference # parses a string from a bank transaction field def self.parse(data) - m = /(^|[^\w\.])FS(?\d+)(\.(?\d+))?(?([A-Za-z]+\d+(\.\d+)?)+)([^\w\.]|$)/.match(data) + m = /(^|[^\w.])FS(?\d+)(\.(?\d+))?(?([A-Za-z]+\d+(\.\d+)?)+)([^\w.]|$)/.match(data) return unless m parts = {} @@ -13,7 +13,7 @@ class BankTransactionReference ret = { group: m[:group].to_i, parts: parts } ret[:user] = m[:user].to_i if m[:user] - return ret + ret end def self.js_code_for_user(user) diff --git a/lib/bank_transactions_csv.rb b/app/lib/bank_transactions_csv.rb similarity index 100% rename from lib/bank_transactions_csv.rb rename to app/lib/bank_transactions_csv.rb diff --git a/lib/date_time_attribute_validate.rb b/app/lib/date_time_attribute_validate.rb similarity index 82% rename from lib/date_time_attribute_validate.rb rename to app/lib/date_time_attribute_validate.rb index 08138d02..23127898 100644 --- a/lib/date_time_attribute_validate.rb +++ b/app/lib/date_time_attribute_validate.rb @@ -27,12 +27,20 @@ module DateTimeAttributeValidate define_method("#{attribute}_date_value=") do |val| self.instance_variable_set("@#{attribute}_is_set", true) self.instance_variable_set("@#{attribute}_date_value", val) - self.send("#{attribute}_date=", val) rescue nil + begin + self.send("#{attribute}_date=", val) + rescue + nil + end end define_method("#{attribute}_time_value=") do |val| self.instance_variable_set("@#{attribute}_is_set", true) self.instance_variable_set("@#{attribute}_time_value", val) - self.send("#{attribute}_time=", val) rescue nil + begin + self.send("#{attribute}_time=", val) + rescue + nil + end end # fallback to field when values are not set @@ -48,11 +56,19 @@ module DateTimeAttributeValidate # validate date and time define_method("#{attribute}_datetime_value_valid") do date = self.instance_variable_get("@#{attribute}_date_value") - unless date.blank? || (Date.parse(date) rescue nil) + unless date.blank? || begin + Date.parse(date) + rescue + nil + end errors.add(attribute, "is not a valid date") # @todo I18n end time = self.instance_variable_get("@#{attribute}_time_value") - unless time.blank? || (Time.parse(time) rescue nil) + unless time.blank? || begin + Time.parse(time) + rescue + nil + end errors.add(attribute, "is not a valid time") # @todo I18n end end diff --git a/lib/financial_transactions_csv.rb b/app/lib/financial_transactions_csv.rb similarity index 100% rename from lib/financial_transactions_csv.rb rename to app/lib/financial_transactions_csv.rb diff --git a/lib/foodsoft/expansion_variables.rb b/app/lib/foodsoft/expansion_variables.rb similarity index 96% rename from lib/foodsoft/expansion_variables.rb rename to app/lib/foodsoft/expansion_variables.rb index bcf67e7a..97f7b6bb 100644 --- a/lib/foodsoft/expansion_variables.rb +++ b/app/lib/foodsoft/expansion_variables.rb @@ -54,8 +54,8 @@ module Foodsoft # @param options [Hash] Extra variables to expand # @return [String] Expanded string def self.expand(str, options = {}) - str.gsub /{{([._a-zA-Z0-9]+)}}/ do - options[$1] || self.get($1) + str.gsub(/{{([._a-zA-Z0-9]+)}}/) do + options[::Regexp.last_match(1)] || self.get(::Regexp.last_match(1)) end end diff --git a/lib/foodsoft_config.rb b/app/lib/foodsoft_config.rb similarity index 99% rename from lib/foodsoft_config.rb rename to app/lib/foodsoft_config.rb index 5a370459..2893a3e3 100644 --- a/lib/foodsoft_config.rb +++ b/app/lib/foodsoft_config.rb @@ -44,6 +44,8 @@ class FoodsoftConfig # @return [ActiveSupport::HashWithIndifferentAccess] Current configuration from configuration file. mattr_accessor :config + mattr_accessor :default_config + # Configuration file location. # Taken from environment variable +FOODSOFT_APP_CONFIG+, # or else +config/app_config.yml+. @@ -189,7 +191,7 @@ class FoodsoftConfig # @return [Hash] Full configuration. def to_hash - keys.to_h { |k| [k, self[k]] } + keys.index_with { |k| self[k] } end # for using active_model_serializer in the api/v1/configs controller @@ -216,7 +218,6 @@ class FoodsoftConfig # end # # @return [Hash] Default configuration values - mattr_accessor :default_config private diff --git a/lib/foodsoft_date_util.rb b/app/lib/foodsoft_date_util.rb similarity index 84% rename from lib/foodsoft_date_util.rb rename to app/lib/foodsoft_date_util.rb index 98dc1c61..a14ad453 100644 --- a/lib/foodsoft_date_util.rb +++ b/app/lib/foodsoft_date_util.rb @@ -6,7 +6,11 @@ module FoodsoftDateUtil schedule = IceCube::Schedule.new(start) schedule.add_recurrence_rule rule_from(options[:recurr]) # @todo handle ical parse errors - occ = (schedule.next_occurrence(from).to_time rescue nil) + occ = begin + schedule.next_occurrence(from).to_time + rescue + nil + end end if options && options[:time] && occ occ = occ.beginning_of_day.advance(seconds: Time.parse(options[:time]).seconds_since_midnight) @@ -17,9 +21,10 @@ module FoodsoftDateUtil # @param p [String, Symbol, Hash, IceCube::Rule] What to return a rule from. # @return [IceCube::Rule] Recurring rule def self.rule_from(p) - if p.is_a? String + case p + when String IceCube::Rule.from_ical(p) - elsif p.is_a? Hash + when Hash IceCube::Rule.from_hash(p) else p diff --git a/lib/foodsoft_file.rb b/app/lib/foodsoft_file.rb similarity index 100% rename from lib/foodsoft_file.rb rename to app/lib/foodsoft_file.rb diff --git a/lib/foodsoft_mail_receiver.rb b/app/lib/foodsoft_mail_receiver.rb similarity index 73% rename from lib/foodsoft_mail_receiver.rb rename to app/lib/foodsoft_mail_receiver.rb index 560e7edd..18e93be3 100644 --- a/lib/foodsoft_mail_receiver.rb +++ b/app/lib/foodsoft_mail_receiver.rb @@ -19,7 +19,7 @@ class FoodsoftMailReceiver < MidiSmtpServer::Smtpd private - def on_rcpt_to_event(ctx, rcpt_to) + def on_rcpt_to_event(_ctx, rcpt_to) recipient = rcpt_to.gsub(/^\s*<\s*(.*)\s*>\s*$/, '\1') @handlers << self.class.find_handler(recipient) rcpt_to @@ -29,20 +29,18 @@ class FoodsoftMailReceiver < MidiSmtpServer::Smtpd end def on_message_data_event(ctx) - begin - @handlers.each do |handler| - handler.call(ctx[:message][:data]) - end - rescue => error - ExceptionNotifier.notify_exception(error, data: ctx) - raise error - ensure - @handlers.clear + @handlers.each do |handler| + handler.call(ctx[:message][:data]) end + rescue => error + ExceptionNotifier.notify_exception(error, data: ctx) + raise error + ensure + @handlers.clear end def self.find_handler(recipient) - m = /(?[^@\.]+)\.(?
[^@]+)(@(?[^@]+))?/.match recipient + m = /(?[^@.]+)\.(?
[^@]+)(@(?[^@]+))?/.match recipient raise "recipient is missing or has an invalid format" if m.nil? raise "Foodcoop '#{m[:foodcoop]}' could not be found" unless FoodsoftConfig.allowed_foodcoop? m[:foodcoop] @@ -51,7 +49,7 @@ class FoodsoftMailReceiver < MidiSmtpServer::Smtpd @@registered_classes.each do |klass| if match = klass.regexp.match(m[:address]) handler = klass.new match - return lambda { |data| handler.received(data) } + return ->(data) { handler.received(data) } end end diff --git a/lib/invoices_csv.rb b/app/lib/invoices_csv.rb similarity index 98% rename from lib/invoices_csv.rb rename to app/lib/invoices_csv.rb index aa20cd08..ebd1f0a9 100644 --- a/lib/invoices_csv.rb +++ b/app/lib/invoices_csv.rb @@ -32,7 +32,7 @@ class InvoicesCsv < RenderCSV t.deposit, t.deposit_credit, t.paid_on, - t.note, + t.note ] end end diff --git a/lib/order_csv.rb b/app/lib/order_csv.rb similarity index 100% rename from lib/order_csv.rb rename to app/lib/order_csv.rb diff --git a/lib/order_pdf.rb b/app/lib/order_pdf.rb similarity index 96% rename from lib/order_pdf.rb rename to app/lib/order_pdf.rb index 034ca51f..8e30ea84 100644 --- a/lib/order_pdf.rb +++ b/app/lib/order_pdf.rb @@ -1,4 +1,4 @@ -class OrderPdf < RenderPDF +class OrderPDF < RenderPDF attr_reader :order def initialize(order, options = {}) @@ -55,7 +55,7 @@ class OrderPdf < RenderPDF end def group_order_article_quantity_with_tolerance(goa) - goa.tolerance > 0 ? "#{goa.quantity} + #{goa.tolerance}" : "#{goa.quantity}" + goa.tolerance > 0 ? "#{goa.quantity} + #{goa.tolerance}" : goa.quantity.to_s end def group_order_article_result(goa) @@ -88,7 +88,7 @@ class OrderPdf < RenderPDF .pluck('groups.name', 'SUM(group_orders.price)', 'ordergroup_id', 'SUM(group_orders.transport)') result.map do |item| - [item.first || stock_ordergroup_name] + item[1..-1] + [item.first || stock_ordergroup_name] + item[1..] end end @@ -103,7 +103,7 @@ class OrderPdf < RenderPDF def each_ordergroup_batch(batch_size) offset = 0 - while true + loop do go_records = ordergroups(offset, batch_size) break unless go_records.any? diff --git a/lib/order_txt.rb b/app/lib/order_txt.rb similarity index 81% rename from lib/order_txt.rb rename to app/lib/order_txt.rb index 5ad1fba6..7f23e705 100644 --- a/lib/order_txt.rb +++ b/app/lib/order_txt.rb @@ -1,5 +1,5 @@ class OrderTxt - def initialize(order, options = {}) + def initialize(order, _options = {}) @order = order end @@ -15,10 +15,10 @@ class OrderTxt text += "****** " + I18n.t('orders.fax.to_address') + "\n\n" text += "#{FoodsoftConfig[:name]}\n#{contact[:street]}\n#{contact[:zip_code]} #{contact[:city]}\n\n" text += "****** " + I18n.t('orders.fax.articles') + "\n\n" - text += "%8s %8s %s\n" % [I18n.t('orders.fax.number'), I18n.t('orders.fax.amount'), I18n.t('orders.fax.name')] + text += format("%8s %8s %s\n", I18n.t('orders.fax.number'), I18n.t('orders.fax.amount'), I18n.t('orders.fax.name')) # now display all ordered articles @order.order_articles.ordered.includes([:article, :article_price]).each do |oa| - text += "%8s %8d %s\n" % [oa.article.order_number, oa.units_to_order.to_i, oa.article.name] + text += format("%8s %8d %s\n", oa.article.order_number, oa.units_to_order.to_i, oa.article.name) end text end diff --git a/lib/ordergroups_csv.rb b/app/lib/ordergroups_csv.rb similarity index 88% rename from lib/ordergroups_csv.rb rename to app/lib/ordergroups_csv.rb index c41d2e83..71a9aaa7 100644 --- a/lib/ordergroups_csv.rb +++ b/app/lib/ordergroups_csv.rb @@ -14,9 +14,9 @@ class OrdergroupsCsv < RenderCSV Ordergroup.human_attribute_name(:break_start), Ordergroup.human_attribute_name(:break_end), Ordergroup.human_attribute_name(:last_user_activity), - Ordergroup.human_attribute_name(:last_order), + Ordergroup.human_attribute_name(:last_order) ] - row + Ordergroup.custom_fields.map { |f| f[:label] } + row + Ordergroup.custom_fields.pluck(:label) end def data @@ -33,7 +33,7 @@ class OrdergroupsCsv < RenderCSV o.break_start, o.break_end, o.last_user_activity, - o.last_order.try(:starts), + o.last_order.try(:starts) ] yield row + Ordergroup.custom_fields.map { |f| o.settings.custom_fields[f[:name]] } end diff --git a/lib/render_csv.rb b/app/lib/render_csv.rb similarity index 100% rename from lib/render_csv.rb rename to app/lib/render_csv.rb diff --git a/lib/render_pdf.rb b/app/lib/render_pdf.rb similarity index 98% rename from lib/render_pdf.rb rename to app/lib/render_pdf.rb index a5cde2b6..aed04011 100644 --- a/lib/render_pdf.rb +++ b/app/lib/render_pdf.rb @@ -18,7 +18,7 @@ class RotatedCell < Prawn::Table::Cell::Text (height + (border_top_width / 2.0) + (border_bottom_width / 2.0)) / tan_rotation end - def styled_width_of(text) + def styled_width_of(_text) options = @text_options.reject { |k| k == :style } with_font { (@pdf.height_of(@content, options) + padding_top + padding_bottom) / tan_rotation } end @@ -156,9 +156,10 @@ class RenderPDF < Prawn::Document def pdf_add_page_breaks?(docid = nil) docid ||= self.class.name.underscore cfg = FoodsoftConfig[:pdf_add_page_breaks] - if cfg.is_a? Array + case cfg + when Array cfg.index(docid.to_s).any? - elsif cfg.is_a? Hash + when Hash cfg[docid.to_s] else cfg diff --git a/lib/spreadsheet_file.rb b/app/lib/spreadsheet_file.rb similarity index 100% rename from lib/spreadsheet_file.rb rename to app/lib/spreadsheet_file.rb diff --git a/lib/templates/haml/scaffold/_form.html.haml b/app/lib/templates/haml/scaffold/_form.html.haml similarity index 100% rename from lib/templates/haml/scaffold/_form.html.haml rename to app/lib/templates/haml/scaffold/_form.html.haml diff --git a/lib/token_verifier.rb b/app/lib/token_verifier.rb similarity index 97% rename from lib/token_verifier.rb rename to app/lib/token_verifier.rb index a8a0f1eb..b481d60f 100644 --- a/lib/token_verifier.rb +++ b/app/lib/token_verifier.rb @@ -21,8 +21,6 @@ class TokenVerifier < ActiveSupport::MessageVerifier # return original message if r.length > 2 r[2] - else - nil end end @@ -32,8 +30,6 @@ class TokenVerifier < ActiveSupport::MessageVerifier class InvalidPrefix < ActiveSupport::MessageVerifier::InvalidSignature; end - protected - def self.secret # secret_key_base for Rails 4, but Rails 3 initializer may still be used Foodsoft::Application.config.secret_key_base || Foodsoft::Application.config.secret_token diff --git a/lib/users_csv.rb b/app/lib/users_csv.rb similarity index 100% rename from lib/users_csv.rb rename to app/lib/users_csv.rb