Class: Teepee::ActionableCommander

Inherits:
Commander
  • Object
show all
Defined in:
lib/teepee/actionable-commander.rb

Instance Attribute Summary

Attributes inherited from Commander

#parser, #scope

Instance Method Summary collapse

Methods inherited from Commander

#backquote, #backslash, #command_error, #command_not_yet_implemented, #dollar, #left_brace, #left_bracket, #left_strip, #pipe, #pipe?, #right_brace, #right_bracket, #right_strip, #space, #squiggle, #strip, #valid_email_address?, #valid_uri?, #variable_not_defined_error, #with_scope

Methods included from CommanderMixins::ThinkingBicycleModels

#bookmarks_folder_id, #folder_id, #forum_id, #image, #keyword_id, #link, #link_id, #mailto, #note_id, #tag_id, #tb_href

Methods included from CommanderMixins::Mathematics

#%, #*, #**, #+, #-, #/, #acos, #acosh, #add_percentage, #asin, #asinh, #atan, #atanh, #ceiling, #cos, #cosh, #degrees2radians, #e, #ensure_numeric, #erf, #erfc, #floor, #gamma, #greater_than, #greater_than_or_equal, #hypot, #i, #ld, #ldexp, #less_than, #less_than_or_equal, #lgamma, #ln, #log, #log10, #mod, #non_numeric_error, #number_from_word, #numeric?, #percent_total, #pi, #radians2degrees, #round, #sin, #sinh, #sqrt, #subtract_percentage, #tan, #tanh, #to_numbers

Methods included from CommanderMixins::Formatting

#b, #big, #br, #del, #enumerate, #enumerate_lowercase, #enumerate_numeric, #enumerate_roman_lowercase, #enumerate_roman_uppercase, #enumerate_uppercase, #h1, #h2, #h3, #h4, #h5, #h6, #html_tag, #it, #item, #itemize, #itemize_circle, #itemize_disc, #itemize_none, #itemize_square, #nbsp, #small, #span_operator, #sub, #sup, #table, #table_data, #table_header, #table_row, #tt, #u

Methods included from CommanderMixins::Control

#case_operator, #comment, #cond_operator, #decrement, #define, #dotimes, #equal, #get_operator, #if_operator, #increment, #is_defined?, #is_scoped?, #let1, #not_equal, #prog1_operator, #progn_operator, #prognil, #undefine, #unless_operator, #update_scopes, #update_variable, #when_operator

Methods included from CommanderMixins::Boolean

#boolean_and, #boolean_nand, #boolean_nor, #boolean_not, #boolean_or, #boolean_xnor, #boolean_xor, #ensure_boolean, #false_constant, #false_constant?, #true_constant, #true_constant?

Constructor Details

#initialize(params) ⇒ ActionableCommander

Returns a new instance of ActionableCommander.



49
50
51
52
53
# File 'lib/teepee/actionable-commander.rb', line 49

def initialize params
  @action_view = params[:action_view]
  @controller = params[:controller]
  super nil
end

Instance Method Details

#id_command_handler(id, klass, singular = klass.to_s.camelcase_to_snakecase, plural = singular.pluralize, partial = "#{plural}/inline", view = "") ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/teepee/actionable-commander.rb', line 55

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_by_id 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



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/teepee/actionable-commander.rb', line 76

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