Module: ChgkRating::Concerns::Searching

Included in:
ChgkRating::Collections::Players, ChgkRating::Collections::Teams
Defined in:
lib/chgk_rating/concerns/searching.rb

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

Some black magic indeed… Creates a Search child class of a given class that changes the URI where the GET request should be sent



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/chgk_rating/concerns/searching.rb', line 9

def self.included(klass)
  klass.const_set(:Search,
                  Class.new(klass) do |*_args|
                    def api_path
                      "#{super}/search"
                    end
                  end)

  # The actual method to perform searching
  # Instantiates a Search class with the given search params
  # and send a GET request to the proper URI (defined above)
  klass.define_singleton_method :search do |params|
    klass.const_get(:Search).new(params)
  end
end