Class: Grapethor::Endpoint
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Grapethor::Endpoint
- Includes:
- Utils, Thor::Actions
- Defined in:
- lib/grapethor/generators/endpoint.rb
Constant Summary
Constants included from Utils
Utils::ATTRS_MAP, Utils::CONFIG_FILENAME, Utils::TEST_FRAMEWORK_DIRNAME
Instance Attribute Summary collapse
-
#api_version ⇒ Object
readonly
Returns the value of attribute api_version.
-
#app_path ⇒ Object
readonly
Returns the value of attribute app_path.
-
#end_desc ⇒ Object
readonly
Returns the value of attribute end_desc.
-
#end_method ⇒ Object
readonly
Returns the value of attribute end_method.
-
#end_name ⇒ Object
readonly
Returns the value of attribute end_name.
-
#end_params ⇒ Object
readonly
Returns the value of attribute end_params.
-
#end_query ⇒ Object
readonly
Returns the value of attribute end_query.
-
#end_query_sample ⇒ Object
readonly
Returns the value of attribute end_query_sample.
-
#end_query_with_params ⇒ Object
readonly
Returns the value of attribute end_query_with_params.
-
#end_resource ⇒ Object
readonly
Returns the value of attribute end_resource.
-
#request_path ⇒ Object
readonly
Returns the value of attribute request_path.
-
#request_path_sample ⇒ Object
readonly
Returns the value of attribute request_path_sample.
Class Method Summary collapse
Instance Method Summary collapse
- #create_endpoint ⇒ Object
- #parse_args_and_opts ⇒ Object
- #prepare_endpoint ⇒ Object
- #validate_target_api ⇒ Object
Instance Attribute Details
#api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
9 10 11 |
# File 'lib/grapethor/generators/endpoint.rb', line 9 def api_version @api_version end |
#app_path ⇒ Object (readonly)
Returns the value of attribute app_path.
9 10 11 |
# File 'lib/grapethor/generators/endpoint.rb', line 9 def app_path @app_path end |
#end_desc ⇒ Object (readonly)
Returns the value of attribute end_desc.
9 10 11 |
# File 'lib/grapethor/generators/endpoint.rb', line 9 def end_desc @end_desc end |
#end_method ⇒ Object (readonly)
Returns the value of attribute end_method.
9 10 11 |
# File 'lib/grapethor/generators/endpoint.rb', line 9 def end_method @end_method end |
#end_name ⇒ Object (readonly)
Returns the value of attribute end_name.
9 10 11 |
# File 'lib/grapethor/generators/endpoint.rb', line 9 def end_name @end_name end |
#end_params ⇒ Object (readonly)
Returns the value of attribute end_params.
9 10 11 |
# File 'lib/grapethor/generators/endpoint.rb', line 9 def end_params @end_params end |
#end_query ⇒ Object (readonly)
Returns the value of attribute end_query.
9 10 11 |
# File 'lib/grapethor/generators/endpoint.rb', line 9 def end_query @end_query end |
#end_query_sample ⇒ Object (readonly)
Returns the value of attribute end_query_sample.
9 10 11 |
# File 'lib/grapethor/generators/endpoint.rb', line 9 def end_query_sample @end_query_sample end |
#end_query_with_params ⇒ Object (readonly)
Returns the value of attribute end_query_with_params.
9 10 11 |
# File 'lib/grapethor/generators/endpoint.rb', line 9 def end_query_with_params @end_query_with_params end |
#end_resource ⇒ Object (readonly)
Returns the value of attribute end_resource.
9 10 11 |
# File 'lib/grapethor/generators/endpoint.rb', line 9 def end_resource @end_resource end |
#request_path ⇒ Object (readonly)
Returns the value of attribute request_path.
9 10 11 |
# File 'lib/grapethor/generators/endpoint.rb', line 9 def request_path @request_path end |
#request_path_sample ⇒ Object (readonly)
Returns the value of attribute request_path_sample.
9 10 11 |
# File 'lib/grapethor/generators/endpoint.rb', line 9 def request_path_sample @request_path_sample end |
Class Method Details
.exit_on_failure? ⇒ Boolean
24 25 26 |
# File 'lib/grapethor/generators/endpoint.rb', line 24 def self.exit_on_failure? true end |
.source_root ⇒ Object
28 29 30 |
# File 'lib/grapethor/generators/endpoint.rb', line 28 def self.source_root File.join(__dir__, '..') end |
Instance Method Details
#create_endpoint ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/grapethor/generators/endpoint.rb', line 102 def create_endpoint report("Creating new endpoint...") do unless File.exist?("#{app_path}/api/#{api_version}/#{end_resource_plural}.rb") directory "templates/endpoint/api/\%api_version\%", "#{app_path}/api/#{api_version}" end insert_into_file "#{app_path}/api/#{api_version}/#{end_resource_plural}.rb", end_content, after: "resource :#{end_resource.pluralize} do\n" insert_into_file "#{app_path}/api/#{api_version}/base.rb", "\s\s\s\smount API#{api_version}::#{end_resource.classify.pluralize}\n", before: "\s\s\s\s# mount API#{api_version}::<ResourceOrEndpointClass>\n" unless File.exist?("#{app_path}/#{test_dirname}/api/#{api_version}/#{end_resource_plural}_#{test_dirname}.rb") directory "templates/endpoint_#{app_test_framework}", app_path end insert_into_file "#{app_path}/#{test_dirname}/api/#{api_version}/#{end_resource_plural}_#{test_dirname}.rb", end_test_content, after: "\s\s### grapethor works here ###\n" end end |
#parse_args_and_opts ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/grapethor/generators/endpoint.rb', line 73 def parse_args_and_opts @end_resource = resource.downcase.singularize @end_name = name.downcase.singularize @end_method = [:method].upcase @end_params = [:params] @end_query = [:query].map { |k, v| [k, v.downcase] }.to_h @end_query_with_params = [:params].merge([:query]).map { |k, v| [k, v.downcase] }.to_h @api_version = [:version].downcase @app_path = [:path] end |
#prepare_endpoint ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/grapethor/generators/endpoint.rb', line 85 def prepare_endpoint prepare_request_path prepare_request_path_sample @end_desc = [:desc].empty? ? "#{end_method} #{request_path}" : [:desc] end |
#validate_target_api ⇒ Object
94 95 96 97 98 99 |
# File 'lib/grapethor/generators/endpoint.rb', line 94 def validate_target_api unless api_version_exists? alert "API version '#{api_version}' does not exist!" exit end end |