Module: CanTango::Permit::Helper::Naming
- Included in:
- Builder::Permit::Base::ClassMethods, Config::Permits::Registration, Macros::Permit, ClassMethods
- Defined in:
- lib/cantango/permit/helper/naming.rb
Instance Method Summary collapse
- #account_name(clazz = nil) ⇒ Object
- #permit_name(clazz = nil) ⇒ Object
- #permit_type(clazz = nil) ⇒ Object
Instance Method Details
#account_name(clazz = nil) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/cantango/permit/helper/naming.rb', line 12 def account_name clazz = nil clazz ||= is_class?(self) ? self : self.class return nil if clazz.name == clazz.name.demodulize top_module = clazz.name.gsub(/::.*/,'') return nil unless /Permits$/ =~ top_module top_module.gsub!(/Account/, '') top_module.gsub(/(.*)Permits/, '\1').underscore.to_sym end |
#permit_name(clazz = nil) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/cantango/permit/helper/naming.rb', line 4 def permit_name clazz = nil clazz ||= is_class?(self) ? self : self.class return nil unless clazz.name =~ /Permit/ namespaces = clazz.name.split('::') name = (namespaces[-2] == 'Permit') ? namespaces.last : namespaces.last.sub(/Permit$/, '') name.underscore.to_sym end |
#permit_type(clazz = nil) ⇒ Object
21 22 23 24 |
# File 'lib/cantango/permit/helper/naming.rb', line 21 def permit_type clazz = nil clazz ||= is_class?(self) ? self : self.class permit_name clazz.superclass end |