class Riveter::Generators::QueryFilterGenerator

Public Class Methods

new(args, *options) click to toggle source
Calls superclass method
# File lib/generators/riveter/query_filter/query_filter_generator.rb, line 13
def initialize(args, *options)
  super
  parse_filter_attributes!
end

Public Instance Methods

create_locale_file() click to toggle source
# File lib/generators/riveter/query_filter/query_filter_generator.rb, line 27
def create_locale_file
  template 'query_filters.en.yml', File.join('config/locales', 'query_filters.en.yml') unless locale_file_exists?
end
create_module_file() click to toggle source
# File lib/generators/riveter/query_filter/query_filter_generator.rb, line 22
def create_module_file
  return if regular_class_path.empty?
  template 'module.rb', File.join('app/query_filters', "#{class_path.join('/')}.rb") if behavior == :invoke
end
create_query_filter_file() click to toggle source
# File lib/generators/riveter/query_filter/query_filter_generator.rb, line 18
def create_query_filter_file
  template 'query_filter.rb', File.join('app/query_filters', class_path, "#{file_name}_query_filter.rb")
end

Protected Instance Methods

locale_file_exists?() click to toggle source
# File lib/generators/riveter/query_filter/query_filter_generator.rb, line 47
def locale_file_exists?
  File.exists?(File.join(destination_root, 'config', 'locales', 'query_filters.en.yml'))
end
parse_filter_attributes!() click to toggle source
# File lib/generators/riveter/query_filter/query_filter_generator.rb, line 35
def parse_filter_attributes!
  self.filter_attributes = (filter_attributes || []).map do |attribute|
    # expected in the form "name", "name:type" or "name:type:required"
    parts = attribute.split(':')
    OpenStruct.new(
      :name => parts.first.underscore,
      :type => ((parts.length > 1) ? parts[1] : 'string'),
      :inject_options => ((parts.length == 3 && parts[2] == 'required') ? ', :required => true' : '')
    )
  end
end