Class: MM::Command::AbstractCommand
- Inherits:
-
Object
- Object
- MM::Command::AbstractCommand
show all
- Defined in:
- lib/mm/cmds/abstract_command.rb
Instance Method Summary
collapse
Instance Method Details
#cache_options ⇒ Object
46
47
48
|
# File 'lib/mm/cmds/abstract_command.rb', line 46
def cache_options
Repository.new[self.class.name] = options
end
|
#card_property?(column_name, obj_value) ⇒ Boolean
87
88
89
|
# File 'lib/mm/cmds/abstract_command.rb', line 87
def card_property?(column_name, obj_value)
obj_value.to_i > 0 && column_name =~ /card_id$/
end
|
#display_value(column_name, obj_value) ⇒ Object
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/mm/cmds/abstract_command.rb', line 76
def display_value(column_name, obj_value)
case
when card_property?(column_name, obj_value)
find_card(:id => obj_value).short_summarization
when user_property?(column_name, obj_value)
team_members.find{|u|u.id==obj_value}.name
else
obj_value
end
end
|
#doc ⇒ Object
42
43
44
|
# File 'lib/mm/cmds/abstract_command.rb', line 42
def doc
puts(respond_to?(:option_parser) ? option_parser : "No document.")
end
|
#options ⇒ Object
32
33
34
35
36
37
|
# File 'lib/mm/cmds/abstract_command.rb', line 32
def options
return @options if @options
@options = Repository.new[self.class.name] || {}
ENV.keys.each { |key| @options[$1.downcase.to_sym] = ENV[key] if key =~ /^mm_(.+)/i }
@options
end
|
#output(message = nil) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/mm/cmds/abstract_command.rb', line 50
def output(message=nil)
if block_given?
output yield
return
elsif message.is_a?(String)
puts message
elsif options[:attrs]
attributes = if options[:attrs].is_a?(String)
options[:attrs].split(',')
else
options[:attrs]
end
attributes.each do |attr_name|
attr_name = attr_name.strip
column_name = if pd = property_definitions.find{|pd| pd.name.downcase == attr_name.downcase}
pd.column_name
else
attr_name
end
output(" * #{attr_name}: #{display_value(column_name, message.send(column_name))}")
end
else
output(message.to_yaml)
end
end
|
#parse(argv) ⇒ Object
39
40
|
# File 'lib/mm/cmds/abstract_command.rb', line 39
def parse(argv)
end
|
#run(argv) ⇒ Object
19
20
21
22
23
24
25
26
|
# File 'lib/mm/cmds/abstract_command.rb', line 19
def run(argv)
if respond_to?(:option_parser)
option_parser.parse!(argv)
end
parse(argv) unless argv.empty?
cache_options
view do_once
end
|
#user_property?(column_name, obj_value) ⇒ Boolean
91
92
93
|
# File 'lib/mm/cmds/abstract_command.rb', line 91
def user_property?(column_name, obj_value)
obj_value.to_i > 0 && column_name =~ /user_id$/
end
|
#view(result) ⇒ Object
28
29
30
|
# File 'lib/mm/cmds/abstract_command.rb', line 28
def view(result)
output result
end
|