module LinkedRails
Constants
- VERSION
Public Class Methods
configurable_class(parent, klass, default: nil, reader: nil)
click to toggle source
# File lib/linked_rails.rb, line 23 def self.configurable_class(parent, klass, default: nil, reader: nil) # rubocop:disable Metrics/AbcSize method = :"#{[parent, klass.to_s.downcase].compact.join('_')}_class" default ||= "LinkedRails::#{[parent&.to_s&.camelize, klass.to_s.classify].compact.join('::')}" mattr_writer method, default: default define_singleton_method reader || method do @model_classes[method] ||= class_variable_get("@@#{method}").constantize end end
host()
click to toggle source
# File lib/linked_rails.rb, line 34 def host # rubocop:disable Style/ClassVars @@host ||= Rails.application.routes.default_url_options[:host]&.split('//')&.last || 'example.com' # rubocop:enable Style/ClassVars end
iri(opts = {})
click to toggle source
# File lib/linked_rails.rb, line 44 def iri(opts = {}) RDF::URI.new(**{scheme: LinkedRails.scheme, host: LinkedRails.host}.merge(opts)) end
scheme()
click to toggle source
# File lib/linked_rails.rb, line 40 def scheme @@scheme ||= Rails.application.routes.default_url_options[:protocol] || :http # rubocop:disable Style/ClassVars end
translate(*args)
click to toggle source
# File lib/linked_rails/translate.rb, line 4 def self.translate(*args) Translate.call(*args) end
translations(translation)
click to toggle source
# File lib/linked_rails/translate.rb, line 8 def self.translations(translation) I18n.available_locales.map do |locale| I18n.with_locale(locale) do value = translation.call RDF::Literal.new(value, language: locale) if value end end.compact end