class InteractionGenerator

Public Instance Methods

create_interaction_file() click to toggle source
# File lib/generators/interaction_generator.rb, line 8
def create_interaction_file
  template "interaction.rb", File.join('app/interactions/', class_path, "#{file_name}.rb")
end

Protected Instance Methods

build_namespaces() click to toggle source
# File lib/generators/interaction_generator.rb, line 34
def build_namespaces
  class_path.reverse.map do |module_name|
    namespaces_layout(module_name)
  end    
end
class_name() click to toggle source
# File lib/generators/interaction_generator.rb, line 16
def class_name
  file_name.camelize
end
interaction_namespaced(&block) click to toggle source
# File lib/generators/interaction_generator.rb, line 20
def interaction_namespaced(&block)
  content = capture(&block)
  content = wrap_in_namespaces(content)
  content = wrap_with_namespace(content) if namespaced?
  concat(content)
end
namespaces_layout(module_name) click to toggle source
# File lib/generators/interaction_generator.rb, line 40
def namespaces_layout(module_name)
  "module #{module_name.camelize}\n%s\nend\n"
end
wrap_in_namespaces(content) click to toggle source
# File lib/generators/interaction_generator.rb, line 27
def wrap_in_namespaces(content)
  namespaces = build_namespaces
  return content unless namespaces.any?
  content = indent(content, namespaces.size * 2).chomp
  namespaces.reduce {|mod, memo| memo % indent(mod).chomp } % content    
end