From 73162156d85889c3458ba09b9ea45704ab86bcae Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 24 Jan 2022 00:18:52 +0900 Subject: [PATCH] class << self for better maintainability --- .../generators/kaminari/views_generator.rb | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/kaminari-core/lib/generators/kaminari/views_generator.rb b/kaminari-core/lib/generators/kaminari/views_generator.rb index e1825b1..829903a 100644 --- a/kaminari-core/lib/generators/kaminari/views_generator.rb +++ b/kaminari-core/lib/generators/kaminari/views_generator.rb @@ -9,8 +9,9 @@ module Kaminari class_option :template_engine, type: :string, aliases: '-e', desc: 'Template engine for the views. Available options are "erb", "haml", and "slim".' class_option :views_prefix, type: :string, desc: 'Prefix for path to put views in.' - def self.banner #:nodoc: - <<-BANNER.chomp + class << self + def banner #:nodoc: + <<-BANNER.chomp rails g kaminari:views THEME [options] Copies all paginator partial templates to your application. @@ -21,6 +22,17 @@ rails g kaminari:views THEME [options] This one is used internally while you don't override the partials. #{themes.map {|t| " - #{t.name}\n#{t.description}"}.join("\n")} BANNER + end + + private + + def themes + @themes ||= GitHubApiHelper.get_files_in_master.group_by {|fn, _| fn[0...(fn.index('/') || 0)]}.delete_if {|fn, _| fn.blank?}.map do |name, files| + Theme.new name, files + end + rescue SocketError + [] + end end desc '' @@ -36,15 +48,6 @@ BANNER end end - private - def self.themes - @themes ||= GitHubApiHelper.get_files_in_master.group_by {|fn, _| fn[0...(fn.index('/') || 0)]}.delete_if {|fn, _| fn.blank?}.map do |name, files| - Theme.new name, files - end - rescue SocketError - [] - end - def download_templates(theme) theme.templates_for(template_engine).each do |template| say " downloading #{template.name} from kaminari_themes..."