Sha256: 2bf2d633562fe13a2fb0fbfea9406269b1b3ccbb7e16a68a963db03151e1555e

Contents?: true

Size: 861 Bytes

Versions: 8

Compression:

Stored size: 861 Bytes

Contents

class User < ActiveRecord::Base
  include Protobuf::ActiveRecord::Model

  attr_accessor :password

  scope :by_guid, lambda { |*guids| where(:guid => guids) }
  scope :by_email, lambda { |*emails| where(:email => emails) }

  attribute_from_proto :first_name, :extract_first_name
  attribute_from_proto :last_name, :extract_last_name
  attribute_from_proto :password, lambda { |proto| proto.password! }

  def self.extract_first_name(proto)
    if proto.has_field?(:name)
      names = proto.name.split(" ")
      first_name = names.first
    end

    first_name
  end

  def self.extract_last_name(proto)
    if proto.has_field?(:name)
      names = proto.name.split(" ")
      names.shift # Drop the first name
      last_name = names.join(" ")
    end

    last_name
  end

  def token
    "key"
  end

  def name
    "#{first_name} #{last_name}"
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
protobuf-activerecord-3.2.0 spec/support/models/user.rb
protobuf-activerecord-3.1.1 spec/support/models/user.rb
protobuf-activerecord-3.1.0 spec/support/models/user.rb
protobuf-activerecord-3.1.0.rc1 spec/support/models/user.rb
protobuf-activerecord-3.1.0.alpha2 spec/support/models/user.rb
protobuf-activerecord-3.1.0.alpha spec/support/models/user.rb
protobuf-activerecord-3.0.2 spec/support/models/user.rb
protobuf-activerecord-3.0.1 spec/support/models/user.rb