class Mumukit::Auth::Slug
Attributes
content[RW]
course[RW]
first[RW]
organization[RW]
repository[RW]
second[RW]
Public Class Methods
any()
click to toggle source
# File lib/mumukit/auth/slug.rb, line 97 def self.any parse '_/_' end
from_options(hash)
click to toggle source
# File lib/mumukit/auth/slug.rb, line 71 def self.from_options(hash) first = hash[:first] || hash[:organization] second = hash[:second] || hash[:repository] || hash[:course] || hash[:content] new(first, second) end
join(*parts)
click to toggle source
# File lib/mumukit/auth/slug.rb, line 77 def self.join(*parts) raise Mumukit::Auth::InvalidSlugFormatError, 'Slugs must have up to two parts' if parts.length > 2 if parts.first.is_a? Hash from_options parts.first else new(*parts.pad_with('_', 2)) end end
join_s(*args)
click to toggle source
# File lib/mumukit/auth/slug.rb, line 87 def self.join_s(*args) join(*args).to_s end
new(first, second)
click to toggle source
# File lib/mumukit/auth/slug.rb, line 17 def initialize(first, second) raise 'slug first part must be non-nil' unless first raise 'slug second part must be non-nil' unless second @first = first @second = second end
normalize(first, second)
click to toggle source
# File lib/mumukit/auth/slug.rb, line 101 def self.normalize(first, second) new(first, second).normalize! end
parse(slug)
click to toggle source
# File lib/mumukit/auth/slug.rb, line 91 def self.parse(slug) validate_slug! slug self.new *slug.split('/') end
Private Class Methods
validate_slug!(slug)
click to toggle source
# File lib/mumukit/auth/slug.rb, line 115 def self.validate_slug!(slug) unless slug =~ /\A[^\/\n]+\/[^\/\n]+\z/ raise Mumukit::Auth::InvalidSlugFormatError, "Invalid slug: #{slug}. It must be in first/second format" end end
Public Instance Methods
==(o)
click to toggle source
# File lib/mumukit/auth/slug.rb, line 37 def ==(o) self.class == o.class && self.normalize.eql?(o.normalize) end
eql?(o)
click to toggle source
# File lib/mumukit/auth/slug.rb, line 41 def eql?(o) self.class == o.class && to_s == o.to_s end
hash()
click to toggle source
# File lib/mumukit/auth/slug.rb, line 45 def hash to_s.hash end
inspect()
click to toggle source
# File lib/mumukit/auth/slug.rb, line 63 def inspect "<Mumukit::Auth::Slug #{to_s}>" end
match_first(first)
click to toggle source
# File lib/mumukit/auth/slug.rb, line 25 def match_first(first) match self.first, first end
match_second(second)
click to toggle source
# File lib/mumukit/auth/slug.rb, line 29 def match_second(second) match self.second, second end
normalize()
click to toggle source
# File lib/mumukit/auth/slug.rb, line 59 def normalize dup.normalize! end
normalize!()
click to toggle source
# File lib/mumukit/auth/slug.rb, line 53 def normalize! @first = normalize_part @first @second = normalize_part @second self end
rebase(new_organizaton)
click to toggle source
# File lib/mumukit/auth/slug.rb, line 33 def rebase(new_organizaton) self.class.new new_organizaton, repository end
to_mumukit_slug()
click to toggle source
# File lib/mumukit/auth/slug.rb, line 67 def to_mumukit_slug self end
to_s()
click to toggle source
# File lib/mumukit/auth/slug.rb, line 49 def to_s "#{first}/#{second}" end
Private Instance Methods
match(pattern, part)
click to toggle source
# File lib/mumukit/auth/slug.rb, line 111 def match(pattern, part) pattern == '_' || pattern == part end
normalize_part(slug_part)
click to toggle source
# File lib/mumukit/auth/slug.rb, line 107 def normalize_part(slug_part) slug_part.split('.').map(&:parameterize).join('.') end