Class: Scenic::UnaffixedName
- Inherits:
-
Object
- Object
- Scenic::UnaffixedName
- Defined in:
- lib/scenic/unaffixed_name.rb
Overview
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.
Class Method Summary collapse
-
.for(name) ⇒ String
Gets the unaffixed name for the provided string.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(name, config:) ⇒ UnaffixedName
constructor
A new instance of UnaffixedName.
Constructor Details
#initialize(name, config:) ⇒ UnaffixedName
Returns a new instance of UnaffixedName.
16 17 18 19 |
# File 'lib/scenic/unaffixed_name.rb', line 16 def initialize(name, config:) @name = name @config = config end |
Class Method Details
.for(name) ⇒ String
Gets the unaffixed name for the provided string
12 13 14 |
# File 'lib/scenic/unaffixed_name.rb', line 12 def self.for(name) new(name, config: ActiveRecord::Base).call end |
Instance Method Details
#call ⇒ Object
21 22 23 24 25 |
# 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 |