Module: Motor::BuildSchema::ActiveStorageAttachmentSchema

Defined in:
lib/motor/build_schema/active_storage_attachment_schema.rb

Class Method Summary collapse

Class Method Details

.callObject

rubocop:disable Metrics/MethodLength, Metrics/AbcSize



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/motor/build_schema/active_storage_attachment_schema.rb', line 9

def call
  model = ActiveStorage::Attachment

  {
    name: model.name.underscore,
    slug: Utils.slugify(model),
    class_name: model.name,
    table_name: model.table_name,
    primary_key: model.primary_key,
    display_name: model.model_name.human(count: 2, default: 'Attachments'),
    display_column: 'filename',
    icon: 'paperclip',
    columns: [
      {
        name: 'id',
        display_name: 'ID',
        column_type: 'integer',
        access_type: 'read_only',
        default_value: nil,
        validators: [],
        format: {},
        is_array: false,
        reference: nil,
        virtual: false
      },
      {
        name: 'path',
        display_name: model.human_attribute_name(:path),
        column_type: 'string',
        access_type: 'read_only',
        default_value: nil,
        validators: [],
        format: {},
        is_array: false,
        reference: nil,
        virtual: true
      },
      {
        name: 'name',
        display_name: model.human_attribute_name(:name),
        column_type: 'string',
        access_type: 'read_write',
        default_value: nil,
        validators: [],
        format: {},
        is_array: false,
        reference: nil,
        virtual: false
      },
      {
        name: 'record_type',
        display_name: model.human_attribute_name(:record_type),
        column_type: 'string',
        access_type: 'read_write',
        default_value: nil,
        validators: [],
        format: {},
        is_array: false,
        reference: nil,
        virtual: false
      },
      {
        name: 'record_id',
        display_name: model.human_attribute_name(:record),
        column_type: 'integer',
        access_type: 'read_write',
        default_value: nil,
        validators: [],
        format: {},
        is_array: false,
        reference: {
          name: 'record',
          display_name: model.human_attribute_name(:record),
          model_name: nil,
          reference_type: 'belongs_to',
          foreign_key: 'record_id',
          polymorphic: true
        },
        virtual: false
      },
      {
        name: 'file',
        display_name: model.human_attribute_name(:file),
        column_type: 'file',
        access_type: 'write_only',
        default_value: nil,
        validators: [],
        format: {},
        is_array: false,
        reference: nil,
        virtual: false
      },
      {
        name: 'created_at',
        display_name: model.human_attribute_name(:created_at),
        column_type: 'datetime',
        access_type: 'read_only',
        default_value: nil,
        validators: [],
        format: {},
        is_array: false,
        reference: nil,
        virtual: false
      }
    ],
    associations: [],
    scopes: [],
    actions: Motor::BuildSchema::Defaults.actions.reject { |e| e[:name] == 'edit' },
    tabs: Motor::BuildSchema::Defaults.tabs,
    visible: false
  }.with_indifferent_access
end