Module: ApiScaffold::Generators::Helper
- Defined in:
- lib/generators/api_scaffold/helper.rb
Instance Method Summary collapse
- #api_address ⇒ Object
- #api_description ⇒ Object
- #api_version_module ⇒ Object
- #api_version_module_with_prefix ⇒ Object
- #class_prefix ⇒ Object
- #controller_class ⇒ Object
- #entity_class ⇒ Object
- #entity_class_name ⇒ Object
- #entity_module_with_prefix ⇒ Object
- #model ⇒ Object
Instance Method Details
#api_address ⇒ Object
47 48 49 |
# File 'lib/generators/api_scaffold/helper.rb', line 47 def api_address controller_class.underscore end |
#api_description ⇒ Object
51 52 53 54 55 56 |
# File 'lib/generators/api_scaffold/helper.rb', line 51 def api_description @api_description ||= ActiveRecord::Base.connection.execute( "SELECT obj_description('public.#{model.table_name}'::regclass) as comment" )[0]['comment'].force_encoding(Encoding::BINARY) end |
#api_version_module ⇒ Object
5 6 7 8 |
# File 'lib/generators/api_scaffold/helper.rb', line 5 def api_version_module @api_version_module ||= ApiScaffolding.config.api_version_modules[['api_version']] || ['api_version'].capitalize end |
#api_version_module_with_prefix ⇒ Object
10 11 12 |
# File 'lib/generators/api_scaffold/helper.rb', line 10 def api_version_module_with_prefix api_version_module.present? ? "::#{api_version_module}" : '' end |
#class_prefix ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/generators/api_scaffold/helper.rb', line 14 def class_prefix # проверяем наличие префикса у класса if class_name.include?('::') class_name.split('::')[0] + '::' else '' end end |
#controller_class ⇒ Object
23 24 25 |
# File 'lib/generators/api_scaffold/helper.rb', line 23 def controller_class class_name.gsub(class_prefix, '').pluralize end |
#entity_class ⇒ Object
31 32 33 |
# File 'lib/generators/api_scaffold/helper.rb', line 31 def entity_class "#{class_name}Entity" end |
#entity_class_name ⇒ Object
35 36 37 |
# File 'lib/generators/api_scaffold/helper.rb', line 35 def entity_class_name entity_module_with_prefix + entity_class end |
#entity_module_with_prefix ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/generators/api_scaffold/helper.rb', line 39 def entity_module_with_prefix dir = ['entity_dir'] value = ApiScaffolding.config.api_version_modules[dir] return '' if dir.blank? || class_name.starts_with?(value) "#{value}::" end |
#model ⇒ Object
27 28 29 |
# File 'lib/generators/api_scaffold/helper.rb', line 27 def model class_name.constantize end |