Class: HeraCms::ApplicationRecord

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/hera_cms/application_record.rb

Direct Known Subclasses

Image, Link, Text

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.identify(identifier) ⇒ Object



6
7
8
# File 'app/models/hera_cms/application_record.rb', line 6

def self.identify(identifier)
  self.find_by(identifier: identifier)
end

Instance Method Details

#editable?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'app/models/hera_cms/application_record.rb', line 10

def editable?
  true
end

#update_seedObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/hera_cms/application_record.rb', line 14

def update_seed
  model = self.class.model_name.plural
  file_name = "hera_database_seed.yml"
  directory_path = File.join(Rails.root, 'db', 'hera_cms')
  @file_path = File.join(directory_path, file_name)

  Dir.mkdir(directory_path) unless File.exists?(directory_path)

  elements = File.exists?(@file_path) ? YAML.load(File.read(@file_path)) : {}

  elements[model] = {} unless elements.key?(model)

  elements[model][self.identifier] = self.as_json.without("id", "created_at", "updated_at")


  File.open(@file_path, "w") { |file| file.write(elements.to_yaml) }
end