Class: MenuMaker::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/menu_maker/path.rb

Defined Under Namespace

Modules: Converter

Constant Summary collapse

METHODS =
%i[get post put patch delete]
PathError =
Class.new StandardError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, path) ⇒ Path

Returns a new instance of Path.



11
12
13
14
15
16
17
18
19
20
# File 'lib/menu_maker/path.rb', line 11

def initialize(method, path)
  method = method.to_sym.downcase

  unless self.class.valid_method? method
    fail PathError, "Method must be one of: #{METHODS.join(', ')}"
  end

  @method = method
  @path   = path.to_s
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/menu_maker/path.rb', line 9

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/menu_maker/path.rb', line 9

def path
  @path
end

Class Method Details

.valid_method?(method) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/menu_maker/path.rb', line 5

def self.valid_method?(method)
  METHODS.include? method
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
25
# File 'lib/menu_maker/path.rb', line 22

def ==(other)
  other = Converter.convert(other)
  method == other.method && path == other.path
end

#to_sObject



27
28
29
# File 'lib/menu_maker/path.rb', line 27

def to_s
  path
end