Class: Mumukit::Auth::Slug
- Inherits:
-
Object
- Object
- Mumukit::Auth::Slug
- Defined in:
- lib/mumukit/auth/slug.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Normalized
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
- .normalize(first, second) ⇒ Object
- .parse(slug) ⇒ Object
Instance Method Summary collapse
- #==(o) ⇒ Object
- #eql?(o) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(first, second) ⇒ Slug
constructor
A new instance of Slug.
- #inspect ⇒ Object
- #match_first(first) ⇒ Object
- #match_second(second) ⇒ Object
- #normalize ⇒ Object
- #normalize! ⇒ Object
- #normalized? ⇒ Boolean
- #normalized_s ⇒ 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 21 22 23 |
# 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 |
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
105 106 107 |
# File 'lib/mumukit/auth/slug.rb', line 105 def self.any parse '_/_' end |
.from_options(hash) ⇒ Object
79 80 81 82 83 |
# File 'lib/mumukit/auth/slug.rb', line 79 def self.(hash) first = hash[:first] || hash[:organization] second = hash[:second] || hash[:repository] || hash[:course] || hash[:content] new(first, second) end |
.join(*parts) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/mumukit/auth/slug.rb', line 85 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
95 96 97 |
# File 'lib/mumukit/auth/slug.rb', line 95 def self.join_s(*args) join(*args).to_s end |
.normalize(first, second) ⇒ Object
109 110 111 |
# File 'lib/mumukit/auth/slug.rb', line 109 def self.normalize(first, second) Normalized.new(first, second) end |
.parse(slug) ⇒ Object
99 100 101 102 103 |
# File 'lib/mumukit/auth/slug.rb', line 99 def self.parse(slug) validate_slug! slug self.new *slug.split('/') end |
Instance Method Details
#==(o) ⇒ Object
37 38 39 |
# File 'lib/mumukit/auth/slug.rb', line 37 def ==(o) o.is_a?(Mumukit::Auth::Slug) && self.normalize.eql?(o.normalize) end |
#eql?(o) ⇒ Boolean
41 42 43 |
# File 'lib/mumukit/auth/slug.rb', line 41 def eql?(o) o.is_a?(Mumukit::Auth::Slug) && to_s == o.to_s end |
#hash ⇒ Object
45 46 47 |
# File 'lib/mumukit/auth/slug.rb', line 45 def hash to_s.hash end |
#inspect ⇒ Object
71 72 73 |
# File 'lib/mumukit/auth/slug.rb', line 71 def inspect "<Mumukit::Auth::Slug #{to_s}>" end |
#match_first(first) ⇒ Object
25 26 27 |
# File 'lib/mumukit/auth/slug.rb', line 25 def match_first(first) match self.first, first end |
#match_second(second) ⇒ Object
29 30 31 |
# File 'lib/mumukit/auth/slug.rb', line 29 def match_second(second) match self.second, second end |
#normalize ⇒ Object
59 60 61 |
# File 'lib/mumukit/auth/slug.rb', line 59 def normalize Normalized.new(first, second) end |
#normalize! ⇒ Object
53 54 55 56 57 |
# File 'lib/mumukit/auth/slug.rb', line 53 def normalize! @first = normalize_part @first @second = normalize_part @second self end |
#normalized? ⇒ Boolean
67 68 69 |
# File 'lib/mumukit/auth/slug.rb', line 67 def normalized? normalize.eql? self end |
#normalized_s ⇒ Object
63 64 65 |
# File 'lib/mumukit/auth/slug.rb', line 63 def normalized_s normalize.to_s end |
#rebase(new_organizaton) ⇒ Object
33 34 35 |
# File 'lib/mumukit/auth/slug.rb', line 33 def rebase(new_organizaton) self.class.new new_organizaton, repository end |
#to_mumukit_slug ⇒ Object
75 76 77 |
# File 'lib/mumukit/auth/slug.rb', line 75 def to_mumukit_slug self end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/mumukit/auth/slug.rb', line 49 def to_s "#{first}/#{second}" end |