Class: Grapethor::Resource
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Grapethor::Resource
- Includes:
- Utils, Thor::Actions
- Defined in:
- lib/grapethor/generators/resource.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.
-
#res_attrs ⇒ Object
readonly
Returns the value of attribute res_attrs.
-
#res_desc ⇒ Object
readonly
Returns the value of attribute res_desc.
-
#res_name ⇒ Object
readonly
Returns the value of attribute res_name.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
9 10 11 |
# File 'lib/grapethor/generators/resource.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/resource.rb', line 9 def app_path @app_path end |
#res_attrs ⇒ Object (readonly)
Returns the value of attribute res_attrs.
9 10 11 |
# File 'lib/grapethor/generators/resource.rb', line 9 def res_attrs @res_attrs end |
#res_desc ⇒ Object (readonly)
Returns the value of attribute res_desc.
9 10 11 |
# File 'lib/grapethor/generators/resource.rb', line 9 def res_desc @res_desc end |
#res_name ⇒ Object (readonly)
Returns the value of attribute res_name.
9 10 11 |
# File 'lib/grapethor/generators/resource.rb', line 9 def res_name @res_name end |
Class Method Details
.exit_on_failure? ⇒ Boolean
17 18 19 |
# File 'lib/grapethor/generators/resource.rb', line 17 def self.exit_on_failure? true end |
.source_root ⇒ Object
21 22 23 |
# File 'lib/grapethor/generators/resource.rb', line 21 def self.source_root File.join(__dir__, '..') end |
Instance Method Details
#create_resource ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/grapethor/generators/resource.rb', line 63 def create_resource report("Creating new resource...") do directory "templates/resource", "#{app_path}" directory "templates/resource_#{app_test_framework}", "#{app_path}" insert_into_file "#{app_path}/api/#{api_version}/base.rb", "\s\s\s\smount API#{api_version}::#{res_name.classify.pluralize}\n", before: "\s\s\s\s# mount API#{api_version}::<ResourceOrEndpointClass>\n" end end |
#parse_args_and_opts ⇒ Object
47 48 49 50 51 52 |
# File 'lib/grapethor/generators/resource.rb', line 47 def parse_args_and_opts @res_name = name.downcase.singularize @res_attrs = [:attrs].delete_if { |k, v| k == 'id' }.map { |k, v| [k, v.downcase] }.to_h @api_version = [:version].downcase @app_path = [:path] end |
#validate_target_api ⇒ Object
55 56 57 58 59 60 |
# File 'lib/grapethor/generators/resource.rb', line 55 def validate_target_api unless api_version_exists? alert "API version '#{api_version}' does not exist!" exit end end |