Class: Terrazzo::Namespace::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/terrazzo/namespace/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(route) ⇒ Resource

Returns a new instance of Resource.



6
7
8
# File 'lib/terrazzo/namespace/resource.rb', line 6

def initialize(route)
  @route = route
end

Instance Attribute Details

#routeObject (readonly)

Returns the value of attribute route.



4
5
6
# File 'lib/terrazzo/namespace/resource.rb', line 4

def route
  @route
end

Instance Method Details

#==(other) ⇒ Object



56
57
58
# File 'lib/terrazzo/namespace/resource.rb', line 56

def ==(other)
  resource_name == other.resource_name
end

#controller_pathObject



14
15
16
# File 'lib/terrazzo/namespace/resource.rb', line 14

def controller_path
  route.defaults[:controller]
end

#dashboardObject



26
27
28
# File 'lib/terrazzo/namespace/resource.rb', line 26

def dashboard
  @dashboard ||= dashboard_class&.new
end

#dashboard_classObject



30
31
32
33
34
# File 'lib/terrazzo/namespace/resource.rb', line 30

def dashboard_class
  Terrazzo::ResourceResolver.new(controller_path).dashboard_class
rescue NameError
  nil
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/terrazzo/namespace/resource.rb', line 60

def eql?(other)
  resource_name == other.resource_name
end

#hashObject



64
65
66
# File 'lib/terrazzo/namespace/resource.rb', line 64

def hash
  resource_name.hash
end


40
41
42
# File 'lib/terrazzo/namespace/resource.rb', line 40

def navigation_group
  dashboard&.navigation_group || "Resources"
end


48
49
50
# File 'lib/terrazzo/namespace/resource.rb', line 48

def navigation_group_order
  dashboard&.navigation_group_order || navigation_group
end


36
37
38
# File 'lib/terrazzo/namespace/resource.rb', line 36

def navigation_label
  dashboard&.navigation_label || resource_name.humanize.pluralize
end


44
45
46
# File 'lib/terrazzo/namespace/resource.rb', line 44

def navigation_order
  dashboard&.navigation_order || navigation_label
end

#resource_nameObject



10
11
12
# File 'lib/terrazzo/namespace/resource.rb', line 10

def resource_name
  controller_path.split("/").last
end

#show_in_navigation?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/terrazzo/namespace/resource.rb', line 52

def show_in_navigation?
  dashboard.nil? || dashboard.show_in_navigation?
end

#to_sObject



18
19
20
# File 'lib/terrazzo/namespace/resource.rb', line 18

def to_s
  resource_name
end

#to_symObject



22
23
24
# File 'lib/terrazzo/namespace/resource.rb', line 22

def to_sym
  resource_name.to_sym
end