Sha256: a40e79c34d3d3f145145000eea2d6a0872e2a94944baadc11a2d616f5855d673

Contents?: true

Size: 1.11 KB

Versions: 11

Compression:

Stored size: 1.11 KB

Contents

class Users
  
  def self.users(count)
    res = []
    for i in 0...count
      res << User.new(i)
    end
    res
  end
end

class User

  attr_accessor :id
  attr_accessor :first_name
  attr_accessor :last_name
  attr_accessor :email
  attr_accessor :phone
  
  
  sandboxed_methods :id, :first_name, :last_name, :email, :phone, :notes, :url_for
  
  def initialize(id)
    @id = id
    @first_name = Faker::Name.first_name
    @last_name = Faker::Name.last_name     
    @email = Faker::Internet.email(@first_name)
    @phone = Faker::PhoneNumber.phone_number
  end
  
  def set_sandbox_context(context)
    @sandbox_context = context
  end
  
  def notes
    @notes ||= build_notes
  end
  
  def build_notes
    res = []
    for i in 0..(rand * 5 + 1).to_i
      res << Note.new(@sandbox_context[:locals][:users])
    end
    res
  end
  
  def url_for(action)
    if action == :edit
      @sandbox_context[:controller].url_for(:controller=>:users, :action=>:edit, :id=>@id)
    elsif action == :send_message
      @sandbox_context[:controller].url_for(:controller=>:users, :action=>:send_message, :id=>@id)
    end
    
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sandboxed_erb-0.4.8 example/users.rb
sandboxed_erb-0.4.7 example/users.rb
sandboxed_erb-0.4.6 example/users.rb
sandboxed_erb-0.4.5 example/users.rb
sandboxed_erb-0.4.4 example/users.rb
sandboxed_erb-0.4.3 example/users.rb
sandboxed_erb-0.4.2 example/users.rb
sandboxed_erb-0.4.1 example/users.rb
sandboxed_erb-0.4.0 example/users.rb
sandboxed_erb-0.3.0 example/users.rb
sandboxed_erb-0.2.0 example/users.rb