From 9cab90cf96a12bcc95c065dba87dcdc53fae38b2 Mon Sep 17 00:00:00 2001 From: Kazuya Takeshima Date: Wed, 26 Jun 2013 15:26:57 +0900 Subject: [PATCH 1/5] Support rails 4. --- src/_rails | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_rails b/src/_rails index 70904ff..614f84f 100644 --- a/src/_rails +++ b/src/_rails @@ -70,7 +70,7 @@ __rails_setup_application_directory() { application_directory="$(pwd)" while [ -n "$application_directory" ]; do - if [ -f "${application_directory}/script/rails" ]; then + if [ -f "${application_directory}/script/rails" -o -f "${application_directory}/bin/rails" ]; then return fi application_directory="${application_directory%/*}" From 4f1684515938da2bb1c1821ab2b12edac5d29cc4 Mon Sep 17 00:00:00 2001 From: Kazuya Takeshima Date: Thu, 27 Jun 2013 19:39:01 +0900 Subject: [PATCH 2/5] Change cache name to use application root directory name. --- src/_rails | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/_rails b/src/_rails index 614f84f..ac494c2 100644 --- a/src/_rails +++ b/src/_rails @@ -180,10 +180,12 @@ __rails_generate_commands() { ) _describe -t rails_generators 'rails generator' rails_generators + local application_directory + __rails_setup_application_directory local cache_name - local -a all_generators - cache_name="rails_${$(pwd)##*/}_all_generators" + cache_name="rails/${application_directory##*/}/all_generators" if ! _retrieve_cache ${cache_name}; then + local -a all_generators all_generators=($(_call_program rails_generators rails generate 2> /dev/null | awk '/^ [a-zA-Z_]+/{ print $1 }')) _store_cache ${cache_name} all_generators fi From 5e499ab4168abb52c9d4969af14e6221fed3634e Mon Sep 17 00:00:00 2001 From: Kazuya Takeshima Date: Thu, 27 Jun 2013 19:41:09 +0900 Subject: [PATCH 3/5] Add cache policy. --- src/_rails | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/_rails b/src/_rails index ac494c2..4a5248d 100644 --- a/src/_rails +++ b/src/_rails @@ -160,6 +160,13 @@ _rails_g() { } __rails_generate_commands() { + local context curcontext="$curcontext" update_policy + + zstyle -s ":completion:${curcontext}:" cache-policy update_policy + if [ -z "$update_policy" ]; then + zstyle ":completion:${curcontext}:" cache-policy _rails_generate_commands_caching_policy + fi + local -a rails_generators rails_generators=( assets:'Stubs out new asset placeholders' @@ -200,6 +207,19 @@ __rails_generate_commands() { done } +_rails_generate_commands_caching_policy() { + local application_directory + __rails_setup_application_directory + + if [ "${application_directory}/Gemfile" -nt "$1" ]; then + return 0 + fi + + local -a oldp + oldp=( "$1"(Nmw+1) ) + (( $#oldp )) +} + _rails_generate_default() { local -a generators_options __rails_setup_generators_options From 80ca790ee51e384991110c1cca15703ac607da41 Mon Sep 17 00:00:00 2001 From: Kazuya Takeshima Date: Wed, 10 Jul 2013 00:36:28 +0900 Subject: [PATCH 4/5] Create generator command dynamically. --- src/_rails | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/_rails b/src/_rails index 4a5248d..cfce87d 100644 --- a/src/_rails +++ b/src/_rails @@ -167,26 +167,6 @@ __rails_generate_commands() { zstyle ":completion:${curcontext}:" cache-policy _rails_generate_commands_caching_policy fi - local -a rails_generators - rails_generators=( - assets:'Stubs out new asset placeholders' - controller:'Stubs out a new controller and its views' - generator:'Stubs out a new generator at lib/generators' - helper:'Stubs out a new helper' - integration_test:'Stubs out a new integration test' - mailer:'Stubs out a new mailer and its views' - migration:'Stubs out a new database migration' - model:'Stubs out a new model' - observer:'Stubs out a new observer' - performance_test:'Stubs out a new performance test' - resource:'Stubs out a new resource including an empty model and controller suitable for a restful, resource-oriented application' - scaffold:'Scaffolds an entire resource, from model and migration to controller and views, along with a full test suite' - scaffold_controller:'Stubs out a scaffolded controller, its seven RESTful actions and related views. Pass the model name, either CamelCased or under_scored' - session_migration:'Creates a migration to add the sessions table used by the ORM session store' - task:'Stubs out a new Rake task' - ) - _describe -t rails_generators 'rails generator' rails_generators - local application_directory __rails_setup_application_directory local cache_name @@ -197,6 +177,10 @@ __rails_generate_commands() { _store_cache ${cache_name} all_generators fi + local -a rails_generators + rails_generators=(${all_generators:#*:*}) + _describe -t rails_generators 'rails generator' rails_generators + local -a -U namespaces local namespace local -a generators From 0cd7ec957bbfa043e00b134285bc203267094e67 Mon Sep 17 00:00:00 2001 From: Kazuya Takeshima Date: Wed, 10 Jul 2013 00:40:14 +0900 Subject: [PATCH 5/5] Add jbuilder generator completion. --- src/_rails | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/_rails b/src/_rails index cfce87d..618f5e3 100644 --- a/src/_rails +++ b/src/_rails @@ -270,6 +270,16 @@ _rails_generate_integration_test() { ': :_guard "^-*" "name"' \ } +_rails_generate_jbuilder() { + local -a generators_options + __rails_setup_generators_options + + _arguments \ + $generators_options \ + ': :_guard "^-*" "name"' \ + '*: :__rails_migration_fields' +} + _rails_generate_mailer() { local -a generators_options __rails_setup_generators_options