Module: Videojuicer::Resource::Relationships::Has::ClassMethods
- Defined in:
- lib/videojuicer/resource/relationships/has.rb
Instance Method Summary collapse
- #has(quantifier, name, options = {}) ⇒ Object
-
#n ⇒ Object
Returns a :many quantifier for the ##has method.
Instance Method Details
#has(quantifier, name, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/videojuicer/resource/relationships/has.rb', line 18 def has(quantifier, name, ={}) = { :class=>name.to_s.capitalize, :foreign_key=>"#{name}_id" }.merge() define_method name do id = self.send([:foreign_key]) klass = ([:class].is_a?(String))? Videojuicer.const_get([:class]) : [:class] return nil unless id begin return klass.get(id) rescue Videojuicer::Exceptions::NoResource return nil end end define_method "#{name}=" do |arg| self.send("#{[:foreign_key]}=", arg.id) end end |
#n ⇒ Object
Returns a :many quantifier for the ##has method.
14 15 16 |
# File 'lib/videojuicer/resource/relationships/has.rb', line 14 def n :many end |