class NamedBase
Attributes
class_name[R]
class_nesting[R]
class_nesting_depth[R]
class_path[R]
file_name[R]
file_path[R]
name[R]
plural_name[R]
singular_name[R]
Public Class Methods
new(runtime_args, runtime_options={})
click to toggle source
Calls superclass method
# File lib/activemessaging/named_base.rb, line 13 def initialize(runtime_args, runtime_options={}) super base_name = self.args.first assign_names!(base_name) end
Protected Instance Methods
assign_names!(name)
click to toggle source
# File lib/activemessaging/named_base.rb, line 22 def assign_names!(name) @name = name base_name, @class_path, @file_path, @class_nesting, @class_nesting_depth = extract_modules(@name) @class_name_without_nesting, @singular_name, @plural_name = inflect_names(base_name) if @class_nesting.empty? @class_name = @class_name_without_nesting else @table_name = @class_nesting.underscore << "_" << @table_name @class_name = "#{@class_nesting}::#{@class_name_without_nesting}" end end
extract_modules(name)
click to toggle source
Extract modules from filesystem-style or ruby-style path:
good/fun/stuff Good::Fun::Stuff
produce the same results.
# File lib/activemessaging/named_base.rb, line 38 def extract_modules(name) modules = name.include?('/') ? name.split('/') : name.split('::') name = modules.pop path = modules.map { |m| m.underscore } file_path = (path + [name.underscore]).join('/') nesting = modules.map { |m| m.camelize }.join('::') [name, path, file_path, nesting, modules.size] end
inflect_names(name)
click to toggle source
# File lib/activemessaging/named_base.rb, line 47 def inflect_names(name) camel = name.camelize under = camel.underscore plural = under.pluralize [camel, under, plural] end