Class: Mayl::Commands::Edit

Inherits:
Object
  • Object
show all
Defined in:
lib/mayl/commands/edit.rb

Overview

Public: The Edit command quickly edits the last value consulted with Get or Set.

Example

command = Edit.new(env, 'es', 'Artículo')
command.execute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, locale, value) ⇒ Edit

Public: Initializes a new Get command.

env - the global environment locale - the locale that we want to edit value - the value to set

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
# File 'lib/mayl/commands/edit.rb', line 19

def initialize(env, locale, value)
  @env    = env
  @key    = @env.last_value
  raise ArgumentError, "You must get or set a key before calling edit" unless @key
  @locale = locale
  @value  = value
end

Instance Attribute Details

#localeObject (readonly)

Returns the value of attribute locale.



12
13
14
# File 'lib/mayl/commands/edit.rb', line 12

def locale
  @locale
end

#valueObject (readonly)

Returns the value of attribute value.



12
13
14
# File 'lib/mayl/commands/edit.rb', line 12

def value
  @value
end

Instance Method Details

#executeObject

Public: Executes the command, editing the @key for the given @locale.

Returns the key.



30
31
32
33
34
35
36
# File 'lib/mayl/commands/edit.rb', line 30

def execute
  locale = locales.detect do |locale|
    locale.name.to_s == @locale.to_s
  end
  locale.set @key, @value
  @key
end