Sha256: 57e0b36443fc4be22d89d76783dcfc57a8bb28db42453b0b1d896a1f7985f2f3

Contents?: true

Size: 838 Bytes

Versions: 10

Compression:

Stored size: 838 Bytes

Contents

class User < ActiveRecord::Base
  include Protoable

  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

  def self.convert_base64_to_string(value)
    value
  end

  def self.convert_email_to_lowercase(value)
    value
  end

  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 name
    "#{first_name} #{last_name}"
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
protobuf-activerecord-1.2.6 spec/support/models/user.rb
protobuf-activerecord-1.2.5 spec/support/models/user.rb
protobuf-activerecord-1.2.4 spec/support/models/user.rb
protobuf-activerecord-1.2.3 spec/support/models/user.rb
protobuf-activerecord-1.2.2 spec/support/models/user.rb
protobuf-activerecord-1.2.1 spec/support/models/user.rb
protobuf-activerecord-1.2.0 spec/support/models/user.rb
protobuf-activerecord-1.2.0.rc1 spec/support/models/user.rb
protobuf-activerecord-1.1.1 spec/support/models/user.rb
protobuf-activerecord-1.1.0 spec/support/models/user.rb