Sha256: 4771915adcd946a2e860888cb84ba2d96f39fdb4fb0fd9ec97ac75914983d06d
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
module ActiveRecord module Generators class RolesGenerator < Rails::Generators::NamedBase desc "Generate roles model for User" argument :role_strategy, :type => :string, :aliases => "-r", :default => 'inline_role', :desc => "Create roles model for user" hook_for :orm def self.source_root @source_root ||= File.expand_path("../../templates", __FILE__) end def apply_role_strategy insert_into_model('user', role_strategy_statement) end protected def match_expr /< (.+?)\w+\s/ end def role_strategy_statement "role_strategy #{role_strategy}" end def role_strategy options[:role_strategy] end def model_file(name) File.join(Rails.root, "app/models/#{name}.rb") end def insert_into_model(model_name, insert_text) model_name = model_name.to_s file = File.new(model_file(model_name)) return if (file.read =~ /#{insert_text}/) gsub_file model_file(model_name), match_expr do |match| match << insert_text end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
roles_active_record-0.1.0 | lib/generators/active_record/roles/roles_generator.rb |