class Scenic::UnaffixedName
The name of a view or table according to rails.
This removes any table name prefix or suffix that is configured via ActiveRecord. This allows, for example, the SchemaDumper
to dump a view with its unaffixed name, consistent with how rails handles table dumping.
Attributes
config[R]
name[R]
Public Class Methods
for(name)
click to toggle source
Gets the unaffixed name for the provided string @return [String]
@param name [String] The (potentially) affixed view name
# File lib/scenic/unaffixed_name.rb, line 12 def self.for(name) new(name, config: ActiveRecord::Base).call end
new(name, config:)
click to toggle source
# File lib/scenic/unaffixed_name.rb, line 16 def initialize(name, config:) @name = name @config = config end
Public Instance Methods
call()
click to toggle source
# File lib/scenic/unaffixed_name.rb, line 21 def call prefix = Regexp.escape(config.table_name_prefix) suffix = Regexp.escape(config.table_name_suffix) name.sub(/\A#{prefix}(.+)#{suffix}\z/, "\\1") end