class ApiMe::Generators::FilterGenerator
Public Instance Methods
association_attribute_names()
click to toggle source
# File lib/generators/api_me/filter/filter_generator.rb, line 41 def association_attribute_names nonpolymorphic_attribute_names + polymorphic_attribute_names end
associations()
click to toggle source
# File lib/generators/api_me/filter/filter_generator.rb, line 25 def associations attributes.select(&:reference?) end
attributes_names()
click to toggle source
# File lib/generators/api_me/filter/filter_generator.rb, line 21 def attributes_names attributes.reject(&:reference?).map { |a| a.name.to_sym } end
create_api_filter_file()
click to toggle source
# File lib/generators/api_me/filter/filter_generator.rb, line 13 def create_api_filter_file template 'filter.rb', File.join('app/filters', "#{singular_name}_filter.rb") end
filter_class_name()
click to toggle source
# File lib/generators/api_me/filter/filter_generator.rb, line 17 def filter_class_name "#{class_name}Filter" end
nonpolymorphic_attribute_names()
click to toggle source
# File lib/generators/api_me/filter/filter_generator.rb, line 29 def nonpolymorphic_attribute_names associations.select { |attr| attr.type.in?(%i[belongs_to references]) } .reject { |attr| attr.attr_options.fetch(:polymorphic, false) } .map { |attr| "#{attr.name}_id".to_sym } end
parent_class_name()
click to toggle source
# File lib/generators/api_me/filter/filter_generator.rb, line 49 def parent_class_name if options[:parent] options[:parent] else 'ApiMe::BaseFilter' end end
polymorphic_attribute_names()
click to toggle source
# File lib/generators/api_me/filter/filter_generator.rb, line 35 def polymorphic_attribute_names associations.select { |attr| attr.type.in?(%i[belongs_to references]) } .select { |attr| attr.attr_options.fetch(:polymorphic, false) } .map { |attr| ["#{attr.name}_id".to_sym, "#{attr.name}_type".to_sym] }.flatten end
strong_parameters()
click to toggle source
# File lib/generators/api_me/filter/filter_generator.rb, line 45 def strong_parameters (attributes_names + association_attribute_names).map(&:inspect).join(', ') end