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



4
5
6
# File 'app/models/hera_cms/application_record.rb', line 4

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

Instance Method Details

#editable?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'app/models/hera_cms/application_record.rb', line 8

def editable?
  true
end

#update_seedObject



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

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