Class: Mumukit::Auth::Slug
- Inherits:
-
Object
- Object
- Mumukit::Auth::Slug
- Defined in:
- lib/mumukit/auth/slug.rb
Instance Attribute Summary collapse
-
#first ⇒ Object
(also: #organization)
Returns the value of attribute first.
-
#second ⇒ Object
(also: #repository, #course, #content)
Returns the value of attribute second.
Class Method Summary collapse
Instance Method Summary collapse
- #==(o) ⇒ Object
-
#initialize(first, second) ⇒ Slug
constructor
A new instance of Slug.
- #match_first(first) ⇒ Object
- #match_second(second) ⇒ Object
- #to_mumukit_slug ⇒ Object
- #to_s ⇒ Object
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
#first ⇒ Object 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 |
#second ⇒ Object 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.(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 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_slug ⇒ Object
38 39 40 |
# File 'lib/mumukit/auth/slug.rb', line 38 def to_mumukit_slug self end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/mumukit/auth/slug.rb', line 34 def to_s "#{first}/#{second}" end |