Class: Feature

Inherits:
Usman::ApplicationRecord show all
Defined in:
app/models/feature.rb

Constant Summary collapse

PUBLISHED =

Constants

"published"
UNPUBLISHED =
"unpublished"
DISABLED =
"disabled"
STATUS =
{ 
  PUBLISHED => "Published", 
  UNPUBLISHED => "Un-Published", 
  DISABLED => "Disabled"
}
STATUS_REVERSE =
{ 
  "Published" => PUBLISHED,
  "Un-Published" => UNPUBLISHED,
  "Disabled" => DISABLED
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.save_row_data(hsh) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/feature.rb', line 47

def self.save_row_data(hsh)

  return if hsh[:name].blank?

  feature = Feature.find_by_name(hsh[:name]) || Feature.new
  feature.name = hsh[:name]
  feature.status = Feature::UNPUBLISHED
  
  # Initializing error hash for displaying all errors altogether
  error_object = Kuppayam::Importer::ErrorHash.new

  if feature.valid?
    begin
      feature.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 feature: #{feature.name}"
    details = "Error! #{feature.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)


139
140
141
# File 'app/models/feature.rb', line 139

def can_be_deleted?
  true
end

#can_be_disabled?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'app/models/feature.rb', line 151

def can_be_disabled?
  published? or unpublished?
end

#can_be_edited?Boolean

Permission Methods


Returns:

  • (Boolean)


135
136
137
# File 'app/models/feature.rb', line 135

def can_be_edited?
  published? or unpublished?
end

#can_be_published?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'app/models/feature.rb', line 143

def can_be_published?
  unpublished? or disabled?
end

#can_be_unpublished?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'app/models/feature.rb', line 147

def can_be_unpublished?
  published? or disabled?
end

#disable!Object

change the status to :suspended Return the status

Examples

>>> feature.disable!
=> "disabled"


128
129
130
# File 'app/models/feature.rb', line 128

def disable!
  self.update_attribute(:status, DISABLED)
end

#disabled?Boolean

  • Return true if the user is disabled, else false.

Examples

>>> feature.disabled?
=> true

Returns:

  • (Boolean)


101
102
103
# File 'app/models/feature.rb', line 101

def disabled?
  (status == DISABLED)
end

#display_nameObject

  • Return full name

Examples

>>> feature.display_name
=> "Products"


162
163
164
# File 'app/models/feature.rb', line 162

def display_name
  "#{name}"
end

#publish!Object

change the status to :published Return the status

Examples

>>> feature.publish!
=> "published"


119
120
121
# File 'app/models/feature.rb', line 119

def publish!
  self.update_attribute(:status, PUBLISHED)
end

#published?Boolean

  • Return true if the user is not published, else false.

Examples

>>> feature.published?
=> true

Returns:

  • (Boolean)


85
86
87
# File 'app/models/feature.rb', line 85

def published?
  (status == PUBLISHED)
end

#unpublish!Object

change the status to :unpublished Return the status

Examples

>>> feature.unpublish!
=> "unpublished"


110
111
112
# File 'app/models/feature.rb', line 110

def unpublish!
  self.update_attribute(:status, UNPUBLISHED)
end

#unpublished?Boolean

  • Return true if the user is unpublished, else false.

Examples

>>> feature.unpublished?
=> true

Returns:

  • (Boolean)


93
94
95
# File 'app/models/feature.rb', line 93

def unpublished?
  (status == UNPUBLISHED)
end