Module: KalturaBox::Entry::Metadata::ClassMethods
- Defined in:
- lib/kaltura_box/entry/metadata/class_methods.rb
Instance Method Summary collapse
- #define_add_method(attr_name) ⇒ Object
-
#define_attribute_methods ⇒ Object
This method is called from with method_missing.
-
#define_get_method(attr_name) ⇒ Object
defines a get methods.
-
#define_set_method(attr_name) ⇒ Object
Defines the set method for a specific Media Entry attribute.
- #evaluate_attribute_method(attr_name, method_definition, method_name = attr_name) ⇒ Object
-
#generated_methods ⇒ Object
Contains the names of the generated attribute methods.
- #generated_methods? ⇒ Boolean
Instance Method Details
#define_add_method(attr_name) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/kaltura_box/entry/metadata/class_methods.rb', line 49 def define_add_method(attr_name) evaluate_attribute_method( attr_name, "def add_#{attr_name}(new_value);add_attribute('#{attr_name}',self.entry_id,new_value);end", "add_#{attr_name}" ) end |
#define_attribute_methods ⇒ Object
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_box/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_box/entry/metadata/class_methods.rb', line 42 def define_get_method(attr_name) evaluate_attribute_method( attr_name, "def get_#{attr_name};get_entry(self.entry_id).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_box/entry/metadata/class_methods.rb', line 32 def define_set_method(attr_name) evaluate_attribute_method( attr_name, "def set_#{attr_name}(new_value);set_attribute('#{attr_name}',self.entry_id,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_box/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_methods ⇒ Object
Contains the names of the generated attribute methods.
7 8 9 |
# File 'lib/kaltura_box/entry/metadata/class_methods.rb', line 7 def generated_methods #:nodoc: @generated_methods ||= Set.new end |
#generated_methods? ⇒ Boolean
11 12 13 |
# File 'lib/kaltura_box/entry/metadata/class_methods.rb', line 11 def generated_methods? !generated_methods.empty? end |