Class: Dsu::CommandServices::AddEntryService
- Inherits:
-
Object
- Object
- Dsu::CommandServices::AddEntryService
- Defined in:
- lib/dsu/command_services/add_entry_service.rb
Overview
This class adds (does NOT update) an entry to an entry group by writing it to the appropriate entry group json file.
Constant Summary
Constants included from Support::Fileable
Support::Fileable::MIGRATION_VERSION_FILE_NAME
Instance Attribute Summary collapse
-
#entry ⇒ Object
readonly
Returns the value of attribute entry.
-
#entry_group ⇒ Object
readonly
Returns the value of attribute entry_group.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(entry:, time:) ⇒ AddEntryService
constructor
:entry is an Entry object :time is a Time object; the time of the entry group.
Methods included from Support::Fileable
#backup_folder_for, #config_file_name, #config_folder, #config_path, #current_project_file, #current_project_file_name, #dsu_folder, #entries_file_name, #entries_folder, #entries_path, #gem_dir, #migration_version_folder, #migration_version_path, #project_file_for, #project_folder_for, #projects_folder, #root_folder, #seed_data_dsu_configuration_for, #seed_data_dsu_folder_for, #temp_folder, #theme_file_name, #themes_folder, #themes_path
Methods included from Support::Descriptable
Methods included from Support::ColorThemable
apply_theme, #prompt_with_options
Constructor Details
#initialize(entry:, time:) ⇒ AddEntryService
:entry is an Entry object :time is a Time object; the time of the entry group.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dsu/command_services/add_entry_service.rb', line 24 def initialize(entry:, time:) raise ArgumentError, 'entry is nil' if entry.nil? raise ArgumentError, 'entry is the wrong object type' unless entry.is_a?(Models::Entry) raise ArgumentError, 'time is nil' if time.nil? raise ArgumentError, 'time is the wrong object type' unless time.is_a?(Time) @entry = entry @time = time @entry_group = Models::EntryGroup.find_or_initialize(time: time) end |
Instance Attribute Details
#entry ⇒ Object
Returns the value of attribute entry.
18 19 20 |
# File 'lib/dsu/command_services/add_entry_service.rb', line 18 def entry @entry end |
#entry_group ⇒ Object
Returns the value of attribute entry_group.
18 19 20 |
# File 'lib/dsu/command_services/add_entry_service.rb', line 18 def entry_group @entry_group end |
#time ⇒ Object
Returns the value of attribute time.
18 19 20 |
# File 'lib/dsu/command_services/add_entry_service.rb', line 18 def time @time end |
Instance Method Details
#call ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/dsu/command_services/add_entry_service.rb', line 35 def call entry.validate! entry_group.entries << entry entry_group.save! entry rescue ActiveModel::ValidationError => e header = I18n.t('headers.entry.could_not_be_added') Views::Shared::Error.new(messages: e., header: header).render end |