Class: Ikbis::Advanced::Media

Inherits:
Base
  • Object
show all
Defined in:
lib/ikbis/advanced/media.rb

Direct Known Subclasses

Photo, Video

Constant Summary collapse

MEDIA_EXTENTION =

Class constants:

  1. MEDIA_EXTENTION: used to override the methods names.

II. RESERVER: List of reserved methods we don’t need to

override.
'media_'
RESERVED =
['initialize' , 'method_missing' , 'method_added']

Instance Attribute Summary

Attributes inherited from Base

#access_token

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#oauth_authentication

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, *args, &block) ⇒ Object

Try to generate the method name if its a valid method name and call the paret class.



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ikbis/advanced/media.rb', line 22

def method_missing(key, *args, &block)
  if @@valid_methods.include?(key.to_s)                    
    (class << self; self; end).class_eval do
      define_method(key) do |*args|
         args.insert(0,"#{@class_extention}.#{key}")
         send "#{MEDIA_EXTENTION}#{key}" , *args
      end
    end
    send "#{key}" , *args
  else
    super
  end
end

Class Method Details

.method_added(name) ⇒ Object

When a method is defined added to the valid_methods array. This is just overriding the ruby hook method(method_added)



46
47
48
49
# File 'lib/ikbis/advanced/media.rb', line 46

def self.method_added(name)
  @@valid_methods ||= []
  @@valid_methods << name.to_s.gsub(MEDIA_EXTENTION , '')
end