Module: PowerApi::GeneratorHelper::ActiveRecordResource
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/power_api/generator_helper/active_record_resource.rb
Overview
rubocop:disable Metrics/ModuleLength
Instance Method Summary collapse
- #attributes_names ⇒ Object
- #attributes_symbols_text_list ⇒ Object
- #camel ⇒ Object
- #camel_plural ⇒ Object
- #class_definition_line ⇒ Object
- #id ⇒ Object
- #optional_resource_attributes ⇒ Object
- #path ⇒ Object
- #permitted_attributes ⇒ Object
- #permitted_attributes_names ⇒ Object
- #permitted_attributes_symbols_text_list ⇒ Object
- #plural ⇒ Object
- #plural_titleized ⇒ Object
- #required_attributes_names ⇒ Object
- #required_resource_attributes ⇒ Object
- #resource_attributes=(collection) ⇒ Object
- #resource_name=(value) ⇒ Object
- #snake_case ⇒ Object
- #titleized ⇒ Object
- #upcase ⇒ Object
- #upcase_plural ⇒ Object
Instance Method Details
#attributes_names ⇒ Object
74 75 76 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 74 def attributes_names extract_attrs_names(resource_attributes) end |
#attributes_symbols_text_list ⇒ Object
100 101 102 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 100 def attributes_symbols_text_list attrs_to_symobls_text_list(attributes_names) end |
#camel ⇒ Object
42 43 44 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 42 def camel resource_name.camelize end |
#camel_plural ⇒ Object
46 47 48 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 46 def camel_plural camel.pluralize end |
#class_definition_line ⇒ Object
70 71 72 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 70 def class_definition_line "class #{camel} < ApplicationRecord\n" end |
#id ⇒ Object
30 31 32 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 30 def id "#{snake_case}_id" end |
#optional_resource_attributes ⇒ Object
96 97 98 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 96 def optional_resource_attributes permitted_attributes.reject { |attr| attr[:required] } end |
#path ⇒ Object
66 67 68 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 66 def path "app/models/#{snake_case}.rb" end |
#permitted_attributes ⇒ Object
86 87 88 89 90 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 86 def permitted_attributes resource_attributes.reject do |attr| [:created_at, :updated_at].include?(attr[:name]) end end |
#permitted_attributes_names ⇒ Object
82 83 84 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 82 def permitted_attributes_names extract_attrs_names(permitted_attributes) end |
#permitted_attributes_symbols_text_list ⇒ Object
104 105 106 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 104 def permitted_attributes_symbols_text_list attrs_to_symobls_text_list(permitted_attributes_names) end |
#plural ⇒ Object
50 51 52 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 50 def plural snake_case.pluralize end |
#plural_titleized ⇒ Object
62 63 64 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 62 def plural_titleized plural.titleize end |
#required_attributes_names ⇒ Object
78 79 80 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 78 def required_attributes_names extract_attrs_names(required_resource_attributes) end |
#required_resource_attributes ⇒ Object
92 93 94 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 92 def required_resource_attributes permitted_attributes.select { |attr| attr[:required] } end |
#resource_attributes=(collection) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 23 def resource_attributes=(collection) attributes = format_attributes(collection) raise PowerApi::GeneratorError.new("at least one attribute must be added") if attributes.none? @resource_attributes = attributes end |
#resource_name=(value) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 9 def resource_name=(value) @resource_name = value if !resource_class raise PowerApi::GeneratorError.new( "Invalid resource name. Must be the snake_case representation of a ruby class" ) end if !resource_is_active_record_model? raise PowerApi::GeneratorError.new("resource is not an active record model") end end |
#snake_case ⇒ Object
54 55 56 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 54 def snake_case resource_name.underscore end |
#titleized ⇒ Object
58 59 60 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 58 def titleized resource_name.titleize end |
#upcase ⇒ Object
34 35 36 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 34 def upcase snake_case.upcase end |
#upcase_plural ⇒ Object
38 39 40 |
# File 'lib/power_api/generator_helper/active_record_resource.rb', line 38 def upcase_plural plural.upcase end |