Class: SwaggerCodegenRails::Konstants::Konstant

Inherits:
Object
  • Object
show all
Defined in:
lib/swagger_codegen_rails/konstants.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, base_dir) ⇒ Konstant

Returns a new instance of Konstant.



30
31
32
33
# File 'lib/swagger_codegen_rails/konstants.rb', line 30

def initialize(path, base_dir)
  @path = path
  @base_dir = base_dir
end

Instance Method Details

#constant(str) ⇒ Object


hoge/foo/bar

> Hoge::Foo::Bar




57
58
59
# File 'lib/swagger_codegen_rails/konstants.rb', line 57

def constant(str)
  str.split("/").map(&:camelize).join("::").constantize
end

#reduct(source, reduction) ⇒ Object


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

> hoge/foo/bar




47
48
49
50
51
# 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!Object


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

> Hoge::Foo::Bar




39
40
41
# File 'lib/swagger_codegen_rails/konstants.rb', line 39

def specify!
  constant(reduct(@path, @base_dir))
end