Module: WCC::Blogs::Utils

Included in:
Collection, CollectionSummary, LinkedBlogPostSummary, Metadata, Post, PostSummary, Property
Defined in:
lib/wcc/blogs/utils.rb

Class Method Summary collapse

Class Method Details

.camelcase(term) ⇒ Object



7
8
9
10
11
12
# File 'lib/wcc/blogs/utils.rb', line 7

def camelcase(term)
  term
    .to_s
    .gsub(%r{(?:_|(/))([a-z\d]*)}) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }
    .gsub(%r{/}, '::')
end

.define_camelcase_alias(*underscore_method_names, &block) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/wcc/blogs/utils.rb', line 14

def define_camelcase_alias(*underscore_method_names, &block)
  underscore_method_names.each do |method|
    attribute = camelcase(method)

    define_method(method) { instance_exec(attribute, &block) }
    alias_method attribute, method if attribute != method
  end
end