Sha256: 91aaaaaf61445f14a662223e21dbbf7c87abcc55fc43684dee3e72b6607228c1

Contents?: true

Size: 1.3 KB

Versions: 26

Compression:

Stored size: 1.3 KB

Contents

module Videojuicer
  module Resource
    module Relationships
      module Has
   
        def self.included(base)
          base.extend(ClassMethods)
          base.include(InstanceMethods)
        end
        
        module ClassMethods
          
          # Returns a :many quantifier for the ##has method.
          def n
            :many
          end
          
          def has(quantifier, name, options={})
            options = {
              :class=>name.to_s.capitalize,
              :foreign_key=>"#{name}_id"
            }.merge(options)
            
            define_method name do
              id = self.send(options[:foreign_key])
              klass = (options[:class].is_a?(String))? Videojuicer.const_get(options[:class]) : options[: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("#{options[:foreign_key]}=", arg.id)
            end
          end
          
        end
        
        module InstanceMethods
          
          private
          def write_has_one_object(object)
          end
          
        end
        
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
vj-sdk-0.8.2 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.8.0.1 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.7.14 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.7.13 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.7.11 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.7.10 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.7.9 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.7.8 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.7.7 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.7.6 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.7.5 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.7.4 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.7.3 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.7.2 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.7.1 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.7.0 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.6.9 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.6.8 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.6.7 lib/videojuicer/resource/relationships/has.rb
vj-sdk-0.6.5 lib/videojuicer/resource/relationships/has.rb