Module: CommandServiceObject::ModelHelper
- Included in:
- Service::Generators::CommandGenerator
- Defined in:
- lib/command_service_object/helpers/model_helper.rb
Instance Method Summary collapse
- #allowed_column_types ⇒ Object
- #ignored_column_names ⇒ Object
- #model_attributes ⇒ Object
- #model_class ⇒ Object
- #model_name ⇒ Object
Instance Method Details
#allowed_column_types ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/command_service_object/helpers/model_helper.rb', line 41 def allowed_column_types { string: 'String', bigint: 'Integer', integer: 'Integer', decimal: 'Float', boolean: 'Boolean', datetime: 'DateTime' } end |
#ignored_column_names ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/command_service_object/helpers/model_helper.rb', line 33 def ignored_column_names %w[ created_at updated_at encrypted_password ] end |
#model_attributes ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/command_service_object/helpers/model_helper.rb', line 15 def model_attributes default_attr = { REPLACE_ME: String } return default_attr if model_class.nil? || model_class.try(:columns_hash).nil? attrs = {} model_class.columns_hash.each do |k, v| next if ignored_column_names.include?(k) type = allowed_column_types[v.type] next if type.nil? attrs[k] = type end attrs end |
#model_class ⇒ Object
9 10 11 12 13 |
# File 'lib/command_service_object/helpers/model_helper.rb', line 9 def model_class Object.const_get(model_name) rescue StandardError nil end |
#model_name ⇒ Object
5 6 7 |
# File 'lib/command_service_object/helpers/model_helper.rb', line 5 def model_name name.camelize end |