Sha256: 37aa66c3a53cdd674d770b84425efb00435aa8553eba7285e988d140ceb1207b

Contents?: true

Size: 1014 Bytes

Versions: 1

Compression:

Stored size: 1014 Bytes

Contents

require 'kangaroo/ruby_adapter/many2one'
require 'kangaroo/ruby_adapter/one2many'

module Kangaroo
  module RubyAdapter
    module Fields
      include Many2one
      include One2many
      
      def add_fields
        @ruby_model.define_multiple_accessors *field_names
      end
      
      def add_associations
        @ruby_model.association_fields.each do |association_field|
          add_association association_field
        end
      end
      
      def add_association association_field
        case association_field.type
        when 'many2one'
          add_many2one_association association_field
        when 'one2many'
          add_one2many_association association_field
        end
      end
      
      protected      
      def define_method_in_model name, &block
        @ruby_model.send :define_method, name, &block
      end
      
      def field_names
        fields.map(&:name) - [:id]
      end
      
      def fields
        @fields ||= @ruby_model.fields
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kangaroo-0.1.0.alpha1 lib/kangaroo/ruby_adapter/fields.rb