class Twimock::User
TODO: 要改善 AccessTokenをUserから分離
Constants
- CHILDREN
- COLUMN_NAMES
- INFO_KEYS
- TABLE_NAME
Public Class Methods
find_by_tiwtter_id_or_email(value)
click to toggle source
# File lib/twimock/user.rb, line 46 def self.find_by_tiwtter_id_or_email(value) user = Twimock::User.find_by_twitter_id(value) user ||= Twimock::User.find_by_email(value) end
new(options={})
click to toggle source
# File lib/twimock/user.rb, line 14 def initialize(options={}) opts = Hashie::Mash.new(options) id = opts.id || opts.identifier @id = (id.to_i > 0) ? id.to_i : (Faker::Number.number(10)).to_i @name = opts.name || create_user_name @twitter_id = opts.twitter_id || @name.downcase.gsub(" ", "_") @email = opts.email || Faker::Internet.email @password = opts.password || Faker::Internet.password @created_at = opts.created_at end
Public Instance Methods
generate_access_token(application_id=nil)
click to toggle source
# File lib/twimock/user.rb, line 32 def generate_access_token(application_id=nil) if application_id application = Twimock::Application.find_by_id(application_id) raise Twimock::Errors::ApplicationNotFound unless application end access_token = Twimock::AccessToken.new({ application_id: application_id }) if self.persisted? access_token.user_id = self.id access_token.save! end access_token end
info()
click to toggle source
# File lib/twimock/user.rb, line 25 def info info_hash = Hashie::Mash.new({}) INFO_KEYS.each { |key| info_hash[key] = self.instance_variable_get("@#{key}") } info_hash.id_str = info_hash.id.to_s info_hash end
Private Instance Methods
create_user_name()
click to toggle source
# File lib/twimock/user.rb, line 53 def create_user_name n = Faker::Name.name (n.include?("'") || n.include?(".")) ? create_user_name : n end