Class: Teepee::ActionableCommander
Instance Method Summary
collapse
Methods inherited from Commander
#%, #*, #**, #+, #-, #/, #acos, #acosh, #asin, #asinh, #atan, #atanh, #b, #backslash, #big, #bookmarks_folder_id, #br, #command_error, #command_not_yet_implemented, #cos, #cosh, #degrees2radians, #del, #e, #ensure_numeric, #erf, #erfc, #folder_id, #forum_id, #gamma, #html_tag, #hypot, #i, #it, #ld, #ldexp, #left_brace, #lgamma, #link_id, #ln, #log, #log10, #pi, #radians2degrees, #right_brace, #sin, #sinh, #small, #sqrt, #sub, #sup, #tag_id, #tan, #tanh, #tb_href, #tt, #u
Constructor Details
#initialize(action_view, controller) ⇒ ActionableCommander
49
50
51
52
|
# File 'lib/teepee/actionable-commander.rb', line 49
def initialize action_view, controller
@action_view = action_view
@controller = controller
end
|
Instance Method Details
#id_command_handler(id, klass, singular = klass.to_s.camelcase_to_snakecase, plural = singular.pluralize, partial = "#{plural}/inline", view = "") ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/teepee/actionable-commander.rb', line 54
def id_command_handler(id,
klass,
singular = klass.to_s.camelcase_to_snakecase,
plural = singular.pluralize,
partial = "#{plural}/inline",
view="")
if not id
command_error "#{singular}_id: error: no #{singular} ID specified"
elsif not id.to_s =~ /\A[0-9]+\z/
command_error "#{singular}_id: error: invalid #{singular} ID specified"
else
thing = eval(klass.to_s).find Integer(id.to_s)
if thing
@action_view.render partial: partial,
locals: {singular.to_sym => thing}
else
command_error "unknown #{singular} ID #{id.to_s}"
end
end
end
|
#user(user) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/teepee/actionable-commander.rb', line 75
def user user
if not user
command_error "user: error: no user specified"
else
the_user = User.smart_find user.to_s
if the_user
@action_view.render partial: 'users/name_link',
locals: {the_user: the_user}
else
command_error "unknown user #{user.to_s}"
end
end
end
|