module SwaggerCodegenRails::Namespace

Public Instance Methods

indent(content, multiplier = 2) click to toggle source
# File lib/swagger_codegen_rails/namespace.rb, line 30
def indent(content, multiplier = 2)
  spaces = " " * multiplier
  content.each_line.map { |line| line.blank? ? line : "#{spaces}#{line}" }.join
end
module_namespacing(&block) click to toggle source
# File lib/swagger_codegen_rails/namespace.rb, line 4
def module_namespacing(&block)
  return unless namespaced?
  content = capture(&block)
  split_namespace.reverse.each do |name|
    content = wrap_with_namespace(content, name)
  end
  concat(content)
end
namespaced?() click to toggle source
# File lib/swagger_codegen_rails/namespace.rb, line 13
def namespaced?
  namespace
end
namespaced_route() click to toggle source
# File lib/swagger_codegen_rails/namespace.rb, line 35
def namespaced_route
  depth = 0
  lines = []

  split_namespace.map(&:underscore).each do |ns|
    lines << indent("namespace :#{ns} do\n", depth*2)
    depth += 1
  end

  lines << indent("resources :swagger, only: :index\n", depth*2)

  until depth.zero?
    depth -= 1
    lines << indent("end\n", depth*2)
  end

  lines.join
end
split_namespace() click to toggle source

hoge/foo/bar

> [“Hoge”, “Foo”, “Bar”]


# File lib/swagger_codegen_rails/namespace.rb, line 26
def split_namespace
  namespace.gsub('.','').split("/").reject(&:blank?).map(&:camelize)
end
wrap_with_namespace(content, namespace) click to toggle source
# File lib/swagger_codegen_rails/namespace.rb, line 17
def wrap_with_namespace(content, namespace)
  content = indent(content).chomp
  "module #{namespace}\n#{content}\nend\n"
end