Class: Oversee::Resource

Inherits:
Object
  • Object
show all
Defined in:
app/models/oversee/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_class:, instance: nil) ⇒ Resource

Returns a new instance of Resource.



7
8
9
10
# File 'app/models/oversee/resource.rb', line 7

def initialize(resource_class:, instance: nil)
  @resource_class = resource_class
  @instance = instance
end

Instance Attribute Details

#associationsObject (readonly)

Associations Structured by association macro



34
35
36
# File 'app/models/oversee/resource.rb', line 34

def associations
  @associations
end

#instanceObject (readonly)

Returns the value of attribute instance.



4
5
6
# File 'app/models/oversee/resource.rb', line 4

def instance
  @instance
end

#resource_classObject (readonly)

Returns the value of attribute resource_class.



2
3
4
# File 'app/models/oversee/resource.rb', line 2

def resource_class
  @resource_class
end

#resource_class_nameObject (readonly)

Returns the value of attribute resource_class_name.



3
4
5
# File 'app/models/oversee/resource.rb', line 3

def resource_class_name
  @resource_class_name
end

Instance Method Details

#columns_for_createObject

Columns



23
24
25
26
# File 'app/models/oversee/resource.rb', line 23

def columns_for_create
  excluded_columns = [resource_class.primary_key, "created_at", "updated_at"]
  resource_class.columns_hash.except(*excluded_columns)
end

#columns_for_showObject



28
29
30
# File 'app/models/oversee/resource.rb', line 28

def columns_for_show

end

#foreign_keysObject



52
53
54
55
56
# File 'app/models/oversee/resource.rb', line 52

def foreign_keys
  resource_class.reflections.map do |name, reflection|
    reflection.foreign_key if reflection.belongs_to?
  end.compact
end

#index_pathObject

Route helpers



13
14
15
# File 'app/models/oversee/resource.rb', line 13

def index_path
  "/resources/#{resource_class_name}"
end

#rich_text_associationsObject



58
59
60
# File 'app/models/oversee/resource.rb', line 58

def rich_text_associations
  @rich_text_associations ||= associations[:has_one].select { |association| association[:rich_text] }
end

#show_pathObject



17
18
19
20
# File 'app/models/oversee/resource.rb', line 17

def show_path
  # Rails.application.routes.url_helpers.resource_path(instance || object, resource_class_name:)
  "/resources/#{resource_class_name}/#{instance.to_param}"
end