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

.from_options(hash) ⇒ Object



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

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



48
49
50
51
52
53
54
55
56
# File 'lib/mumukit/auth/slug.rb', line 48

def self.join(*parts)
  raise '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



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

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

.parse(slug) ⇒ Object



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

def self.parse(slug)
  validate_slug! slug

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

Instance Method Details

#==(o) ⇒ Object



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

def ==(o)
  self.class == o.class && to_s == o.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

#to_mumukit_slugObject



38
39
40
# File 'lib/mumukit/auth/slug.rb', line 38

def to_mumukit_slug
  self
end

#to_sObject



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

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