Skip to content

Commit

Permalink
Add #each_with_role into BluePrint::Generators::Base
Browse files Browse the repository at this point in the history
  • Loading branch information
rosylilly committed Mar 14, 2014
1 parent 7b4c4b9 commit 46f30b4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 7 additions & 0 deletions lib/generators/blue_print/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@ def models_with_roles
def roles
models_with_roles.map(&:last).flatten.uniq
end

def each_with_role(&block)
roles.each do |role|
@role = role
yield role
end
end
end
end
3 changes: 1 addition & 2 deletions lib/generators/rails/blue_print_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def create_context_file
end

def create_behavior_files
roles.each do |role|
@role = role
each_with_role do |role|
template 'role.rb', File.join(
'app/blue_prints', class_path, "#{file_name}_context", "#{role.downcase}.rb"
)
Expand Down
3 changes: 1 addition & 2 deletions lib/generators/rspec/blue_print_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def create_context_spec_file
end

def create_behavior_files
roles.each do |role|
@role = role
each_with_role do |role|
template 'role_spec.rb', File.join(
'spec/blue_prints', class_path, "#{file_name}_context", "#{role.downcase}_spec.rb"
)
Expand Down

0 comments on commit 46f30b4

Please sign in to comment.