Class: MM::Console::CardResourceCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/mm/console/card_resource_command.rb

Instance Method Summary collapse

Constructor Details

#initialize(command, card_resource) ⇒ CardResourceCommand

Returns a new instance of CardResourceCommand.



15
16
17
18
# File 'lib/mm/console/card_resource_command.rb', line 15

def initialize(command, card_resource)
  @command = command
  @card_resource = card_resource
end

Instance Method Details

#execute(runtime) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mm/console/card_resource_command.rb', line 20

def execute(runtime)
  case
  when @command =~ /^transitions$/
    runtime[:list] = MM::Console::SelectingList.new(@card_resource.transitions(runtime), MM::Console::CardTransition)
  when @command =~ /^properties$/
    (runtime[:api].property_definitions || []).inject({}) do |map, prop|
      if value = CardResourceCommand.new(prop.column_name, @card_resource).execute(runtime)
        map[prop.name.to_sym] = value
      end
      map
    end.to_yaml
  when @card_resource.respond_to?(@command)
    @card_resource.send(@command)
  when prop = find_property_definition(runtime, @command)
    value = @card_resource.send(prop.column_name)
    case prop.data_type
    when 'user'
      if member = runtime[:api].team_members.detect{|m| m.id == value}
        value = member.name
      end
    when 'card'
      if card = runtime[:api].find_card_by_number(value)
        value = card.name
      end
    end
    value
  when runtime[@command.to_sym]
    NoResourceCommand.new(@command).execute(runtime)
  when @card_resource.transitions(runtime).any?{|t| t.to_s.downcase == @command.to_s.downcase}
    Transition.new(:command => @command, :card_number => @card_resource.number).execute(runtime)
  else
    SystemCmd.execute_as_cmd(runtime, @command)
  end
end

#find_property_definition(runtime, name) ⇒ Object



55
56
57
# File 'lib/mm/console/card_resource_command.rb', line 55

def find_property_definition(runtime, name)
  (runtime[:api].property_definitions || []).detect{|prop_def| prop_def.name.downcase == name.downcase}
end