Class: Dhatu::TeamMember

Inherits:
ApplicationRecord show all
Includes:
Featureable, Publishable
Defined in:
app/models/dhatu/team_member.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.save_row_data(hsh) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/models/dhatu/team_member.rb', line 34

def self.save_row_data(hsh)
  # Initializing error hash for displaying all errors altogether
  error_object = Kuppayam::Importer::ErrorHash.new

  return error_object if hsh[:name].to_s.strip.blank?

  team_member = Dhatu::TeamMember.find_by_name(hsh[:name].to_s.strip) || Dhatu::TeamMember.new
  team_member.name = hsh[:name].to_s.strip
  team_member.designation = hsh[:designation].to_s.strip
  team_member.description = hsh[:description].to_s.strip
  
  team_member.linked_in_url = hsh[:linked_in_url].to_s.strip
  team_member.google_plus_url = hsh[:google_plus_url].to_s.strip
  team_member.facebook_url = hsh[:facebook_url].to_s.strip
  team_member.twitter_url = hsh[:twitter_url].to_s.strip
  
  # team_member.category = Dhatu::Category.find_by_name(hsh[:category])
  team_member.status = hsh[:status].to_s.strip || PUBLISHED
  team_member.featured = hsh[:featured].to_s.strip || true
  team_member.priority = hsh[:priority].to_s.strip || 1

  if team_member.valid?
    begin
      team_member.save!
    rescue Exception => e
      summary = "uncaught #{e} exception while handling connection: #{e.message}"
      details = "Stack trace: #{e.backtrace.map {|l| "  #{l}\n"}.join}"
      error_object.errors << { summary: summary, details: details }        
    end
  else
    summary = "Error while saving team_member: #{team_member.name}"
    details = "Error! #{team_member.errors.full_messages.to_sentence}"
    error_object.errors << { summary: summary, details: details }
  end
  return error_object
end

Instance Method Details

#can_be_deleted?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'app/models/dhatu/team_member.rb', line 92

def can_be_deleted?
  status?(:removed)
end

#can_be_edited?Boolean

Permission Methods


Returns:

  • (Boolean)


88
89
90
# File 'app/models/dhatu/team_member.rb', line 88

def can_be_edited?
  status?(:published) or status?(:unpublished)
end

#display_nameObject



81
82
83
# File 'app/models/dhatu/team_member.rb', line 81

def display_name
  "#{name_was}"
end

#to_paramObject

Generic Methods




77
78
79
# File 'app/models/dhatu/team_member.rb', line 77

def to_param
  "#{id}-#{name.parameterize[0..32]}"
end