class SwaggerCodegenRails::Konstants::Konstant

Public Class Methods

new(path, base_dir) click to toggle source
# File lib/swagger_codegen_rails/konstants.rb, line 30
def initialize(path, base_dir)
  @path = path
  @base_dir = base_dir
end

Public Instance Methods

constant(str) click to toggle source

hoge/foo/bar

> Hoge::Foo::Bar


# File lib/swagger_codegen_rails/konstants.rb, line 57
def constant(str)
  str.split("/").map(&:camelize).join("::").constantize
end
reduct(source, reduction) click to toggle source

app/controllers/concerns/hoge/foo/bar.rb

> hoge/foo/bar


# File lib/swagger_codegen_rails/konstants.rb, line 47
def reduct(source, reduction)
  File.join(File.dirname(source.sub(reduction, '')),
            File.basename(source, 
                          File.extname(source))).sub(/\A\//,'')
end
specify!() click to toggle source

app/controllers/concerns/hoge/foo/bar.rb

> Hoge::Foo::Bar


# File lib/swagger_codegen_rails/konstants.rb, line 39
def specify!
  constant(reduct(@path, @base_dir))
end