Class: SafeDb::Rename

Inherits:
EditVerse show all
Defined in:
lib/controller/edit/rename.rb

Overview

The rename use case when applied at the verse level changes the stated line keyname.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from EditVerse

#execute

Methods inherited from Controller

#check_post_conditions, #check_pre_conditions, #execute, #flow, #initialize, #open_remote_backend_location, #post_validation, #pre_validation, #read_verse, #set_verse, #update_verse

Constructor Details

This class inherits a constructor from SafeDb::Controller

Instance Attribute Details

#new_name=(value) ⇒ Object (writeonly)

The id of the current chapter, verse or line entity to be renamed is the now_name and its new name is the new_name.



12
13
14
# File 'lib/controller/edit/rename.rb', line 12

def new_name=(value)
  @new_name = value
end

#now_name=(value) ⇒ Object (writeonly)

The id of the current chapter, verse or line entity to be renamed is the now_name and its new name is the new_name.



12
13
14
# File 'lib/controller/edit/rename.rb', line 12

def now_name=(value)
  @now_name = value
end

Instance Method Details

#edit_verseObject

Find the line key named now_name and replace it with the provided new_name. The validation for keynames applies, both must be provided and the now_name must exist. This use case also renames file keys.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/controller/edit/rename.rb', line 17

def edit_verse()

# @todo refactor to recognise file values using isMap rather than the string prefix
# @todo refactor the Remove, Show, Read and Write use cases as well as this one.

  exit(100) unless has_line?()

  current_value = @verse[ @now_name ]

# @todo instead of store and delete use the hash key rename method
  @verse.store( @new_name, current_value ) unless is_file?()
  @verse.store( "#{Indices::INGESTED_FILE_LINE_NAME_KEY}#{@new_name}", current_value ) if is_file?()

  @verse.delete( "#{Indices::INGESTED_FILE_LINE_NAME_KEY}#{@now_name}" )
  @verse.delete( @now_name )

end