Class: ActiveRecord::Zuul::Generators::SubjectGenerator
- Inherits:
-
Generators::Base
- Object
- Generators::Base
- ActiveRecord::Zuul::Generators::SubjectGenerator
show all
- Includes:
- Zuul::Generators::OrmHelpers
- Defined in:
- lib/generators/zuul/subject_generator.rb
Instance Method Summary
collapse
#migration_exists?, #migration_path, #model_exists?, #model_path
Instance Method Details
#generate_model ⇒ Object
15
16
17
|
# File 'lib/generators/zuul/subject_generator.rb', line 15
def generate_model
invoke "active_record:model", [name].concat(attributes.map {|attr| "#{attr.name}:#{attr.type}" }), :migration => true unless model_exists? && behavior == :invoke
end
|
#inject_zuul_content ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/generators/zuul/subject_generator.rb', line 19
def inject_zuul_content
content = <<CONTENT
# Setup authorization for your subject model
acts_as_authorization_subject
CONTENT
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
|