Sha256: e3eab29fbebbc2d19d2276c448d39367f025d67088d0e4dc07db4867deb43de8

Contents?: true

Size: 870 Bytes

Versions: 2

Compression:

Stored size: 870 Bytes

Contents

module Dash
  class ResourceGenerator < Rails::Generators::NamedBase
    
    source_root File.expand_path('../templates', __FILE__)
    
    def add_scope
      insert_into_file "app/models/#{singular_name}.rb", after: /class #{singular_name.camelize}(.*)/ do
        "\n\n  scope :filter, ->(term) { where('', term: \"%\#{term}%\") }"
      end
    end

    def create_templates
      @param_singular = ":#{singular_name}"
      @param_plural = ":#{plural_name}"
      @instance_singular = "@#{singular_name}"
      @instance_plural = "@#{plural_name}"
      @index_path = "dash_#{index_helper}_path"
      template 'resource_controller.rb', "app/controllers/dash/#{table_name}_controller.rb"
      template 'form.html.erb', "app/views/dash/#{table_name}/form.html.erb"
      template 'index.html.erb', "app/views/dash/#{table_name}/index.html.erb"
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails_dash-0.1.4 lib/generators/dash/resource_generator.rb
rails_dash-0.1.3 lib/generators/dash/resource_generator.rb