Class: BottledDecoratorGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/bottled_decorator/bottled_decorator_generator.rb

Instance Method Summary collapse

Instance Method Details

#generate_bottled_serviceObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/generators/bottled_decorator/bottled_decorator_generator.rb', line 6

def generate_bottled_service
  puts "Generating Bottled Decorator: #{name}"
  create_file "app/decorators/#{file_name}.rb", <<-File
class #{class_name}
include BottledDecorator

#{ "".tap do |str|
    attributes.each do |attribute|
      puts "injecting method: #{attribute.name}"
        str << "
def #{attribute.name}
  # access the decorated object through the @component instance variable
  # note, you dont need to call methods of the component in the instance variable.
  # if your decorated model or class has a user_name method, you can just call user_name.
end
"
    end
  end
}

end
  File
end