lib/infoboxer/media_wiki/traits.rb in infoboxer-0.3.3 vs lib/infoboxer/media_wiki/traits.rb in infoboxer-0.4.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + module Infoboxer class MediaWiki # DSL for defining "traits" for some site. # # More docs (and possible refactoring) to follow. @@ -55,11 +57,11 @@ # # Again, you can look at current # [English Wikipedia traits](https://github.com/molybdenum-99/infoboxer/blob/master/lib/infoboxer/definitions/en.wikipedia.org.rb) # for example implementation. def for(domain, &block) - Traits.domains[domain].tap { |c| c && c.instance_eval(&block) } || + Traits.domains[domain]&.instance_eval(&block) || Class.new(self, &block).domain(domain) end # @private alias_method :default, :new @@ -112,9 +114,10 @@ end end def ns_aliases(base) return [base] if @site_info.empty? + main = @site_info['namespaces'].values.detect { |n| n['canonical'] == base } [base, main['*']] + @site_info['namespacealiases'] .select { |a| a['id'] == main['id'] }.flat_map { |n| n['*'] } .compact.uniq