Class: Grapethor::Api

Inherits:
Thor::Group
  • Object
show all
Includes:
Utils, Thor::Actions
Defined in:
lib/grapethor/generators/api.rb

Constant Summary

Constants included from Utils

Utils::ATTRS_MAP, Utils::CONFIG_FILENAME, Utils::TEST_FRAMEWORK_DIRNAME

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_versionObject (readonly)

Returns the value of attribute api_version


9
10
11
# File 'lib/grapethor/generators/api.rb', line 9

def api_version
  @api_version
end

#app_pathObject (readonly)

Returns the value of attribute app_path


9
10
11
# File 'lib/grapethor/generators/api.rb', line 9

def app_path
  @app_path
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)

14
15
16
# File 'lib/grapethor/generators/api.rb', line 14

def self.exit_on_failure?
  true
end

.source_rootObject


18
19
20
# File 'lib/grapethor/generators/api.rb', line 18

def self.source_root
  File.join(__dir__, '..')
end

Instance Method Details

#create_apiObject


49
50
51
52
53
54
55
56
57
# File 'lib/grapethor/generators/api.rb', line 49

def create_api
  report("Creating new API...") do
    directory 'templates/api', app_path
    directory "templates/api_#{app_test_framework}", app_path
    insert_into_file "#{app_path}/api/base.rb",
                     "\s\s\s\smount API#{api_version}::Base\n",
                     :before => "\s\s\s\s# mount API<VERSION>::Base\n"
  end
end

#parse_args_and_optsObject


32
33
34
35
# File 'lib/grapethor/generators/api.rb', line 32

def parse_args_and_opts
  @api_version = version.downcase
  @app_path    = options[:path]
end

#validate_target_appObject


38
39
40
41
42
43
44
45
46
# File 'lib/grapethor/generators/api.rb', line 38

def validate_target_app
  unless app_dir_exists?
    alert <<~MSG
            Directory '#{app_path}' does not seem to be generated by Grapethor or root application directory.\n
            Please 'cd' into application root diretory or use '--path' option.
          MSG
    exit
  end
end