Sha256: f11a83a73e357c6f6c7c4e116a6743abd9e0339f3dbe7c9cea675734ce1be523

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require 'active_record'

module AeUsersMigrator
  module Export
    class Account < ActiveRecord::Base
      belongs_to :person, :class_name => "AeUsersMigrator::Export::Person"
    end

    class EmailAddress < ActiveRecord::Base
      belongs_to :person, :class_name => "AeUsersMigrator::Export::Person"
    end

    class OpenIdIdentity < ActiveRecord::Base
      belongs_to :person, :class_name => "AeUsersMigrator::Export::Person"
    end

    class Person < ActiveRecord::Base
      has_many :email_addresses, :class_name => "AeUsersMigrator::Export::EmailAddress"
      has_one :account, :class_name => "AeUsersMigrator::Export::Account"
      has_many :open_id_identities, :class_name => "AeUsersMigrator::Export::OpenIdIdentity"
      has_and_belongs_to_many :roles, :class_name => "AeUsersMigrator::Export::Role"

      def as_json(options = {})
        json = super(options)
        if json['person']
          json = json['person']
        end

        %w{email_addresses account open_id_identities roles}.each do |assn|
          json[assn] = self.send(assn).as_json
        end

        json
      end
    end

    class Role < ActiveRecord::Base
      has_and_belongs_to_many :people, :class_name => "AeUsersMigrator::Export::Person"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ae_users_migrator-1.0.6 lib/ae_users_migrator/export.rb