Module: KalturaFu::Entry::Metadata::ClassMethods

Defined in:
lib/kaltura_fu/entry/metadata/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#define_add_method(attr_name) ⇒ Object



49
50
51
52
53
54
# File 'lib/kaltura_fu/entry/metadata/class_methods.rb', line 49

def define_add_method(attr_name) 
  evaluate_attribute_method( attr_name, 
    "def add_#{attr_name}(entry,new_value);add_attribute('#{attr_name}',entry,new_value);end", 
    "add_#{attr_name}"
  )
end

#define_attribute_methodsObject

This method is called from with method_missing. It generates actual methods for all the valid Kaltura::Media Entry methods the first time a dynamic getter/setter/adder is called.



20
21
22
23
24
25
26
27
# File 'lib/kaltura_fu/entry/metadata/class_methods.rb', line 20

def define_attribute_methods
  return if generated_methods?
  valid_entry_attributes.each do |name|
    define_set_method(name)
    define_get_method(name)
    define_add_method(name) if valid_add_attribute?(name)
  end        
end

#define_get_method(attr_name) ⇒ Object

defines a get methods



42
43
44
45
46
47
# File 'lib/kaltura_fu/entry/metadata/class_methods.rb', line 42

def define_get_method(attr_name)
  evaluate_attribute_method( attr_name, 
    "def get_#{attr_name}(entry);get_entry(entry).send('#{attr_name}');end", 
    "get_#{attr_name}"
  )
end

#define_set_method(attr_name) ⇒ Object

Defines the set method for a specific Media Entry attribute



32
33
34
35
36
37
# File 'lib/kaltura_fu/entry/metadata/class_methods.rb', line 32

def define_set_method(attr_name) 
  evaluate_attribute_method( attr_name, 
    "def set_#{attr_name}(entry,new_value);set_attribute('#{attr_name}',entry,new_value);end", 
    "set_#{attr_name}"
  )
end

#evaluate_attribute_method(attr_name, method_definition, method_name = attr_name) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/kaltura_fu/entry/metadata/class_methods.rb', line 56

def evaluate_attribute_method(attr_name, method_definition, method_name=attr_name) 
  generated_methods << method_name

  begin
    class_eval(method_definition, __FILE__, __LINE__) 
  rescue SyntaxError => err
    generated_methods.delete(attr_name) 
  end
end

#generated_methodsObject

Contains the names of the generated attribute methods.



7
8
9
# File 'lib/kaltura_fu/entry/metadata/class_methods.rb', line 7

def generated_methods #:nodoc:
  @generated_methods ||= Set.new
end

#generated_methods?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/kaltura_fu/entry/metadata/class_methods.rb', line 11

def generated_methods?
  !generated_methods.empty?
end