Now we check the given record or name is a relatable instance or class to avoid trying to render goals for records which don't have a goals association. Note for now we are ignoring the case where we pass a controller_path for an unsupported class (for example, `legislation/proposals` or `budgets/headings`) because we never use it. We might need to revisit this case in the future. Co-Authored-By: Javi Martín <javim@elretirao.net>
49 lines
962 B
Ruby
49 lines
962 B
Ruby
class SDG::ProcessEnabled
|
|
include SettingsHelper
|
|
attr_reader :record_or_name
|
|
|
|
def initialize(record_or_name)
|
|
@record_or_name = record_or_name
|
|
end
|
|
|
|
def enabled?
|
|
feature?("sdg") && feature?(process_name) && setting["sdg.process.#{process_name}"] && relatable?
|
|
end
|
|
|
|
def name
|
|
if record_or_name.respond_to?(:downcase)
|
|
record_or_name
|
|
else
|
|
record_or_name.class.name
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def process_name
|
|
if controller_path_name?
|
|
name.split("/").first
|
|
else
|
|
if module_name == "Legislation"
|
|
"legislation"
|
|
else
|
|
module_name.constantize.table_name
|
|
end
|
|
end
|
|
end
|
|
|
|
def controller_path_name?
|
|
name == name.downcase
|
|
end
|
|
|
|
def module_name
|
|
name.split("::").first
|
|
end
|
|
|
|
def relatable?
|
|
return true if controller_path_name?
|
|
|
|
(SDG::Related::RELATABLE_TYPES & [record_or_name.class.name, record_or_name]).any?
|
|
end
|
|
end
|