Class: Command::OgCommands::HasManyEditCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/command-set/og.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Command

raw_stderr, raw_stdout, wrap_stderr, wrap_stdout

Class Method Details

.add_to(kind) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/command-set/og.rb', line 224

def add_to(kind)
  define_method(:kind) do
    return kind.to_s.singular
  end

  action do
    add(item)
  end

  undo do
    remove(item)
  end
  defined_sense
end

.defined_senseObject



196
197
198
199
200
201
202
203
# File 'lib/command-set/og.rb', line 196

def defined_sense
  class << self
    alias_method :add_to, :no_more_add_or_remove
    alias_method :remove_from, :no_more_add_or_remove
    def defined_sense
    end
  end
end

.find_a(target_class, find_by) ⇒ Object



205
206
207
# File 'lib/command-set/og.rb', line 205

def find_a(target_class, find_by)
  argument OgArgument.new(:item, target_class, find_by)
end

.no_more_add_or_removeObject

Raises:

  • (NoMethodError)


191
192
193
# File 'lib/command-set/og.rb', line 191

def no_more_add_or_remove
  raise NoMethodError,  "Can't add_to and remove_from with same command!"
end

.remove_from(kind) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/command-set/og.rb', line 209

def remove_from(kind)
  define_method(:kind) do
    return kind.to_s.singular
  end

  action do
    remove(item)
  end

  undo do
    add(item)
  end
  defined_sense
end

Instance Method Details

#add(item) ⇒ Object



176
177
178
# File 'lib/command-set/og.rb', line 176

def add(item)
  owner.__send__("add_#{kind}", item)
end

#ownerObject



186
187
188
# File 'lib/command-set/og.rb', line 186

def owner
  subject.current_state.last
end

#remove(item) ⇒ Object



180
181
182
# File 'lib/command-set/og.rb', line 180

def remove(item)
  owner.__send__("remove_#{kind}", item)
end