Module: Dockly::Util::DSL::ClassMethods
- Defined in:
- lib/dockly/util/dsl.rb
Instance Method Summary collapse
- #[](sym) ⇒ Object
- #default_values ⇒ Object
- #demodulize(path) ⇒ Object
- #generate_unique_name ⇒ Object
- #instances ⇒ Object
- #new!(options = {}, &block) ⇒ Object
- #underscore(camel_cased_word) ⇒ Object
Instance Method Details
#[](sym) ⇒ Object
121 122 123 |
# File 'lib/dockly/util/dsl.rb', line 121 def [](sym) instances[sym] end |
#default_values ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/dockly/util/dsl.rb', line 81 def default_values @default_values ||= if self.superclass.respond_to?(:default_values) Marshal.load(Marshal.dump(self.superclass.default_values)) else {} end end |
#demodulize(path) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/dockly/util/dsl.rb', line 93 def demodulize(path) if i = path.rindex('::') path[(i+2)..-1] else path end end |
#generate_unique_name ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/dockly/util/dsl.rb', line 112 def generate_unique_name name = nil (0..(1.0 / 0.0)).each do |n| name = :"#{demodulize(self.name)}_#{n}" break unless instances.has_key?(name) end name end |
#instances ⇒ Object
89 90 91 |
# File 'lib/dockly/util/dsl.rb', line 89 def instances @instances ||= {} end |
#new!(options = {}, &block) ⇒ Object
10 11 12 13 |
# File 'lib/dockly/util/dsl.rb', line 10 def new!( = {}, &block) inst = new(, &block) instances[inst.name] = inst end |
#underscore(camel_cased_word) ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/dockly/util/dsl.rb', line 101 def underscore(camel_cased_word) word = camel_cased_word.to_s.dup word.gsub!('::', '/') word.gsub!(/(?:([A-Za-z\d])|^)(#{/(?=a)b/})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" } word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2') word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') word.tr!("-", "_") word.downcase! word end |