Hi, I''d like to add Rails 3 compatible generator to acts_as_taggable_on gem (all it does is call "migration_template" method) and got a problem with "next_migration_number" method not being implemented. For ActiveRecord this method is defined in ActiveRecord::Generators::Base class, which inherits from NamedBase class. How can I use it inside my generator, which inherits from Rails::Generators::Base? How to use "hook_for :orm" here, so that the proper "next_migration_number" method definition is be used? Cheers, Szymek -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
If you look at the scaffold generator, it is able to apply the correct model/migration generator depending on the orm setting in application.rb. This is handled transparently as I see it. It simply calls the correct migration and model generators with a name corresponding to the orm setting. Check out my http://github.com/kristianmandrup/mongo_model_r3 for an example. This can be used by http://github.com/kristianmandrup/very_nifty_generators Which contains a scaffold generator. This calls the mongo_mapper generator if orm is set to :mongo_mapper and so on... Something similar should be possible with migrations. Also see: http://guides.rails.info/generators.html for more details ;) Good luck! Kristian On Jan 29, 9:54 pm, szimek <szi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''d like to add Rails 3 compatible generator to acts_as_taggable_on > gem (all it does is call "migration_template" method) and got a > problem with "next_migration_number" method not being implemented. > > For ActiveRecord this method is defined in > ActiveRecord::Generators::Base class, which inherits from NamedBase > class. How can I use it inside my generator, which inherits from > Rails::Generators::Base? How to use "hook_for :orm" here, so that the > proper "next_migration_number" method definition is be used? > > Cheers, > Szymek-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks, but the problem is that if I add the following line to my generator: hook_for :orm, :as => "migration" it invokes i.e. ActiveRecord::Generators::Migration and it says that the name attribute is missing, probably because AR::G::Migration inherits from AR::G::Base, which inherits from Rails::Generators::NamedBase. I don''t want to specify migration name, as it''s already hardcoded in my generator, I just want to add a proper prefix (i.e. timestamp), which is added by the "next_migration_number" method. All I need for my generator is to be able to access "migration_template" method and "next_migration_number" depending on ORM selected. It works fine if I simply copy "next_migration_number" method from ActiveRecord::Generators::Base, but I doubt it''s the proper way to do it :) Here''s how it looks currently: http://gist.github.com/290534. BTW. Are there Rails 3 API docs available anywhere? I can''t generate my own, because I got the following error: "wrong constant name ./DOC/ TEMPLATE/HORO" On Jan 30, 12:11 am, Kristian <kmand...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> If you look at the scaffold generator, it is able to apply the correct > model/migration generator depending on the orm setting in > application.rb. > This is handled transparently as I see it. It simply calls the correct > migration and model generators with a name corresponding to the orm > setting. > Check out myhttp://github.com/kristianmandrup/mongo_model_r3for an > example. This can be used byhttp://github.com/kristianmandrup/very_nifty_generators > Which contains a scaffold generator. This calls the mongo_mapper > generator if orm is set to :mongo_mapper and so on... > Something similar should be possible with migrations. > > Also see:http://guides.rails.info/generators.htmlfor more details ;) > > Good luck! > > Kristian > > On Jan 29, 9:54 pm, szimek <szi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi, > > > I''d like to add Rails 3 compatible generator to acts_as_taggable_on > > gem (all it does is call "migration_template" method) and got a > > problem with "next_migration_number" method not being implemented. > > > For ActiveRecord this method is defined in > > ActiveRecord::Generators::Base class, which inherits from NamedBase > > class. How can I use it inside my generator, which inherits from > > Rails::Generators::Base? How to use "hook_for :orm" here, so that the > > proper "next_migration_number" method definition is be used? > > > Cheers, > > Szymek-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
If you have a conventional migration, you can invoke the migration generator explicitly: class ActsAsTaggableOnMigrationGenerator < Rails::Generators::Base invoke "migration", %(add_fields_to_tags name:string label:string) end However, if you need a customized template, currently you have to copy the logic that gets the migration number. Maybe we could expose that as a class method, so you just need to do: ActiveRecord::Generators::Base.next_migration_number Feel free to work in a patch and assign to me when it''s done. If not in mood for a patch, please create a ticket on Lighthouse and assign to me, so I can tackle it later. On Jan 30, 1:46 pm, szimek <szi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks, but the problem is that if I add the following line to my > generator: > > hook_for :orm, :as => "migration" > > it invokes i.e. ActiveRecord::Generators::Migration and it says that > the name attribute is missing, probably because AR::G::Migration > inherits from AR::G::Base, which inherits from > Rails::Generators::NamedBase. I don''t want to specify migration name, > as it''s already hardcoded in my generator, I just want to add a proper > prefix (i.e. timestamp), which is added by the "next_migration_number" > method. > > All I need for my generator is to be able to access > "migration_template" method and "next_migration_number" depending on > ORM selected. It works fine if I simply copy "next_migration_number" > method from ActiveRecord::Generators::Base, but I doubt it''s the > proper way to do it :) > > Here''s how it looks currently:http://gist.github.com/290534. > > BTW. Are there Rails 3 API docs available anywhere? I can''t generate > my own, because I got the following error: "wrong constant name ./DOC/ > TEMPLATE/HORO" > > On Jan 30, 12:11 am, Kristian <kmand...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > If you look at the scaffold generator, it is able to apply the correct > > model/migration generator depending on the orm setting in > > application.rb. > > This is handled transparently as I see it. It simply calls the correct > > migration and model generators with a name corresponding to the orm > > setting. > > Check out myhttp://github.com/kristianmandrup/mongo_model_r3foran > > example. This can be used byhttp://github.com/kristianmandrup/very_nifty_generators > > Which contains a scaffold generator. This calls the mongo_mapper > > generator if orm is set to :mongo_mapper and so on... > > Something similar should be possible with migrations. > > > Also see:http://guides.rails.info/generators.htmlformore details ;) > > > Good luck! > > > Kristian > > > On Jan 29, 9:54 pm, szimek <szi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi, > > > > I''d like to add Rails 3 compatible generator to acts_as_taggable_on > > > gem (all it does is call "migration_template" method) and got a > > > problem with "next_migration_number" method not being implemented. > > > > For ActiveRecord this method is defined in > > > ActiveRecord::Generators::Base class, which inherits from NamedBase > > > class. How can I use it inside my generator, which inherits from > > > Rails::Generators::Base? How to use "hook_for :orm" here, so that the > > > proper "next_migration_number" method definition is be used? > > > > Cheers, > > > Szymek-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
So the solution for now is to make the "next_migration_number" method inside my generator to call a class method. However, assuming that generators for other ORMs like DataMapper or Sequel also follow this convention, how can I check which ORM is used by the application, so that I can change the path to the template and call the proper ActiveModel::Generarators::Base.next_migration_number method? On Jan 30, 2:31 pm, José Valim <jose.va...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> If you have a conventional migration, you can invoke the migration > generator explicitly: > > class ActsAsTaggableOnMigrationGenerator < Rails::Generators::Base > invoke "migration", %(add_fields_to_tags name:string label:string) > end > > However, if you need a customized template, currently you have to copy > the logic that gets the migration number. Maybe we could expose that > as a class method, so you just need to do: > > ActiveRecord::Generators::Base.next_migration_number > > Feel free to work in a patch and assign to me when it''s done. If not > in mood for a patch, please create a ticket on Lighthouse and assign > to me, so I can tackle it later. > > On Jan 30, 1:46 pm, szimek <szi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Thanks, but the problem is that if I add the following line to my > > generator: > > > hook_for :orm, :as => "migration" > > > it invokes i.e. ActiveRecord::Generators::Migration and it says that > > the name attribute is missing, probably because AR::G::Migration > > inherits from AR::G::Base, which inherits from > > Rails::Generators::NamedBase. I don''t want to specify migration name, > > as it''s already hardcoded in my generator, I just want to add a proper > > prefix (i.e. timestamp), which is added by the "next_migration_number" > > method. > > > All I need for my generator is to be able to access > > "migration_template" method and "next_migration_number" depending on > > ORM selected. It works fine if I simply copy "next_migration_number" > > method from ActiveRecord::Generators::Base, but I doubt it''s the > > proper way to do it :) > > > Here''s how it looks currently:http://gist.github.com/290534. > > > BTW. Are there Rails 3 API docs available anywhere? I can''t generate > > my own, because I got the following error: "wrong constant name ./DOC/ > > TEMPLATE/HORO" > > > On Jan 30, 12:11 am, Kristian <kmand...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > If you look at the scaffold generator, it is able to apply the correct > > > model/migration generator depending on the orm setting in > > > application.rb. > > > This is handled transparently as I see it. It simply calls the correct > > > migration and model generators with a name corresponding to the orm > > > setting. > > > Check out myhttp://github.com/kristianmandrup/mongo_model_r3foran > > > example. This can be used byhttp://github.com/kristianmandrup/very_nifty_generators > > > Which contains a scaffold generator. This calls the mongo_mapper > > > generator if orm is set to :mongo_mapper and so on... > > > Something similar should be possible with migrations. > > > > Also see:http://guides.rails.info/generators.htmlformoredetails ;) > > > > Good luck! > > > > Kristian > > > > On Jan 29, 9:54 pm, szimek <szi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi, > > > > > I''d like to add Rails 3 compatible generator to acts_as_taggable_on > > > > gem (all it does is call "migration_template" method) and got a > > > > problem with "next_migration_number" method not being implemented. > > > > > For ActiveRecord this method is defined in > > > > ActiveRecord::Generators::Base class, which inherits from NamedBase > > > > class. How can I use it inside my generator, which inherits from > > > > Rails::Generators::Base? How to use "hook_for :orm" here, so that the > > > > proper "next_migration_number" method definition is be used? > > > > > Cheers, > > > > Szymek-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
It should be Rails::Generators::Migration.next_migration_number, not ActiveModel::Generarators::Base.next_migration_number :) On Jan 30, 3:30 pm, szimek <szi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So the solution for now is to make the "next_migration_number" method > inside my generator to call a class method. > > However, assuming that generators for other ORMs like DataMapper or > Sequel also follow this convention, how can I check which ORM is used > by the application, so that I can change the path to the template and > call the proper ActiveModel::Generarators::Base.next_migration_number > method? > > On Jan 30, 2:31 pm, José Valim <jose.va...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > If you have a conventional migration, you can invoke the migration > > generator explicitly: > > > class ActsAsTaggableOnMigrationGenerator < Rails::Generators::Base > > invoke "migration", %(add_fields_to_tags name:string label:string) > > end > > > However, if you need a customized template, currently you have to copy > > the logic that gets the migration number. Maybe we could expose that > > as a class method, so you just need to do: > > > ActiveRecord::Generators::Base.next_migration_number > > > Feel free to work in a patch and assign to me when it''s done. If not > > in mood for a patch, please create a ticket on Lighthouse and assign > > to me, so I can tackle it later. > > > On Jan 30, 1:46 pm, szimek <szi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Thanks, but the problem is that if I add the following line to my > > > generator: > > > > hook_for :orm, :as => "migration" > > > > it invokes i.e. ActiveRecord::Generators::Migration and it says that > > > the name attribute is missing, probably because AR::G::Migration > > > inherits from AR::G::Base, which inherits from > > > Rails::Generators::NamedBase. I don''t want to specify migration name, > > > as it''s already hardcoded in my generator, I just want to add a proper > > > prefix (i.e. timestamp), which is added by the "next_migration_number" > > > method. > > > > All I need for my generator is to be able to access > > > "migration_template" method and "next_migration_number" depending on > > > ORM selected. It works fine if I simply copy "next_migration_number" > > > method from ActiveRecord::Generators::Base, but I doubt it''s the > > > proper way to do it :) > > > > Here''s how it looks currently:http://gist.github.com/290534. > > > > BTW. Are there Rails 3 API docs available anywhere? I can''t generate > > > my own, because I got the following error: "wrong constant name ./DOC/ > > > TEMPLATE/HORO" > > > > On Jan 30, 12:11 am, Kristian <kmand...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > If you look at the scaffold generator, it is able to apply the correct > > > > model/migration generator depending on the orm setting in > > > > application.rb. > > > > This is handled transparently as I see it. It simply calls the correct > > > > migration and model generators with a name corresponding to the orm > > > > setting. > > > > Check out myhttp://github.com/kristianmandrup/mongo_model_r3foran > > > > example. This can be used byhttp://github.com/kristianmandrup/very_nifty_generators > > > > Which contains a scaffold generator. This calls the mongo_mapper > > > > generator if orm is set to :mongo_mapper and so on... > > > > Something similar should be possible with migrations. > > > > > Also see:http://guides.rails.info/generators.htmlformoredetails;) > > > > > Good luck! > > > > > Kristian > > > > > On Jan 29, 9:54 pm, szimek <szi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Hi, > > > > > > I''d like to add Rails 3 compatible generator to acts_as_taggable_on > > > > > gem (all it does is call "migration_template" method) and got a > > > > > problem with "next_migration_number" method not being implemented. > > > > > > For ActiveRecord this method is defined in > > > > > ActiveRecord::Generators::Base class, which inherits from NamedBase > > > > > class. How can I use it inside my generator, which inherits from > > > > > Rails::Generators::Base? How to use "hook_for :orm" here, so that the > > > > > proper "next_migration_number" method definition is be used? > > > > > > Cheers, > > > > > Szymek-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.