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
- .any ⇒ Object
- .from_options(hash) ⇒ Object
- .join(*parts) ⇒ Object
- .join_s(*args) ⇒ Object
- .parse(slug) ⇒ Object
Instance Method Summary collapse
- #==(o) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(first, second) ⇒ Slug
constructor
A new instance of Slug.
- #inspect ⇒ Object
- #match_first(first) ⇒ Object
- #match_second(second) ⇒ Object
- #rebase(new_organizaton) ⇒ 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
.any ⇒ Object
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.(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 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 |
#hash ⇒ Object
40 41 42 |
# File 'lib/mumukit/auth/slug.rb', line 40 def hash to_s.hash end |
#inspect ⇒ Object
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_slug ⇒ Object
52 53 54 |
# File 'lib/mumukit/auth/slug.rb', line 52 def to_mumukit_slug self end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/mumukit/auth/slug.rb', line 44 def to_s "#{first}/#{second}" end |