Class: Mumukit::Auth::Slug

Inherits:
Object
  • Object
show all
Defined in:
lib/mumukit/auth/slug.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(first, second) ⇒ Slug

Returns a new instance of Slug.



17
18
19
20
# File 'lib/mumukit/auth/slug.rb', line 17

def initialize(first, second)
  @first = first
  @second = second
end

Instance Attribute Details

#firstObject Also known as: organization

Returns the value of attribute first.



9
10
11
# File 'lib/mumukit/auth/slug.rb', line 9

def first
  @first
end

#secondObject Also known as: repository, course, content

Returns the value of attribute second.



9
10
11
# File 'lib/mumukit/auth/slug.rb', line 9

def second
  @second
end

Class Method Details

.anyObject



82
83
84
# File 'lib/mumukit/auth/slug.rb', line 82

def self.any
  parse '_/_'
end

.from_options(hash) ⇒ Object



56
57
58
59
60
# File 'lib/mumukit/auth/slug.rb', line 56

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) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/mumukit/auth/slug.rb', line 62

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) ⇒ Object



72
73
74
# File 'lib/mumukit/auth/slug.rb', line 72

def self.join_s(*args)
  join(*args).to_s
end

.parse(slug) ⇒ Object



76
77
78
79
80
# File 'lib/mumukit/auth/slug.rb', line 76

def self.parse(slug)
  validate_slug! slug

  self.new *slug.split('/')
end

Instance Method Details

#==(o) ⇒ Object Also known as: eql?



34
35
36
# File 'lib/mumukit/auth/slug.rb', line 34

def ==(o)
  self.class == o.class && to_s == o.to_s
end

#hashObject



40
41
42
# File 'lib/mumukit/auth/slug.rb', line 40

def hash
  to_s.hash
end

#inspectObject



48
49
50
# File 'lib/mumukit/auth/slug.rb', line 48

def inspect
  "<Mumukit::Auth::Slug #{to_s}>"
end

#match_first(first) ⇒ Object



22
23
24
# File 'lib/mumukit/auth/slug.rb', line 22

def match_first(first)
  match self.first, first
end

#match_second(second) ⇒ Object



26
27
28
# File 'lib/mumukit/auth/slug.rb', line 26

def match_second(second)
  match self.second, second
end

#rebase(new_organizaton) ⇒ Object



30
31
32
# File 'lib/mumukit/auth/slug.rb', line 30

def rebase(new_organizaton)
  self.class.new new_organizaton, repository
end

#to_mumukit_slugObject



52
53
54
# File 'lib/mumukit/auth/slug.rb', line 52

def to_mumukit_slug
  self
end

#to_sObject



44
45
46
# File 'lib/mumukit/auth/slug.rb', line 44

def to_s
  "#{first}/#{second}"
end