Class: ActiveRecord::Generators::TollGenerator
Instance Method Summary
collapse
#migration_exists?, #migration_path, #model_exists?, #model_path
Instance Method Details
#copy_toll_migration ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/generators/active_record/toll_generator.rb', line 13
def copy_toll_migration
if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
migration_template "existing_migration.rb", "db/migrate/add_toll_to_#{table_name}.rb"
else
migration_template "migration.rb", "db/migrate/toll_create_#{table_name}.rb"
end
end
|
#generate_model ⇒ Object
21
22
23
|
# File 'lib/generators/active_record/toll_generator.rb', line 21
def generate_model
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
end
|
#inject_toll_content ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/generators/active_record/toll_generator.rb', line 25
def inject_toll_content
content = %q{ tollify}
class_path = if namespaced?
class_name.to_s.split("::")
else
[class_name]
end
indent_depth = class_path.size - 1
content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
inject_into_class(model_path, class_path.last, content) if model_exists?
end
|
#migration_data ⇒ Object
39
40
41
42
43
|
# File 'lib/generators/active_record/toll_generator.rb', line 39
def migration_data
%Q{
## Toll model fields
t.string :authentication_token}
end
|