Module: ABingoCampingPlugin::Controllers
- Defined in:
- lib/camping-abingo.rb
Overview
Controllers module for the ABingo Camping Plugin. The module will be plugged in to the main app controllers module using:
- extend to add class methods to the app controllers module
-
include_abingo_controllers to dynamically plugin the ABingo and Helpers modules inside each controller class
(this is why the call must be the last statement in the controllers module)
Example:
module CampingABingoTest::Controllers
extend ABingoCampingPlugin::Controllers
# …
include_abingo_controllers
end
Class Method Summary collapse
-
.common_abingo_controllers ⇒ Object
Returns the source code for all common ABingo controllers.
Instance Method Summary collapse
-
#include_abingo_controllers ⇒ Object
Includes the ABingo and Helpers modules inside each controller class using class_eval (this is why the call must be the last statement in the controllers module).
Class Method Details
.common_abingo_controllers ⇒ Object
Returns the source code for all common ABingo controllers
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 |
# File 'lib/camping-abingo.rb', line 963 def self.common_abingo_controllers " class ABingoMarkHuman < R '/abingo/mark_human'\n include ABingoCampingPlugin::ABingo\n include ABingoCampingPlugin::Helpers\n \n def post\n textual_result = \"1\"\n begin\n a = @input.a.to_i\n b = @input.b.to_i\n c = @input.c.to_i\n if (@env['REQUEST_METHOD'] == 'POST' && (a + b == c))\n Abingo.human!\n else\n textual_result = \"0\"\n end\n rescue #If a bot doesn't pass a, b, or c, to_i will fail. This scarfs up the exception, to save it from polluting our logs.\n textual_result = \"0\"\n end\n \n return textual_result\n end\n end\n \n class ABingoDashboard < R '/abingo/dashboard'\n include ABingoCampingPlugin::ABingo\n include ABingoCampingPlugin::Helpers\n \n def get\n @experiments = ABingoCampingPlugin::Models::Experiment.all\n render :abingo_dashboard\n end\n end \n \n class ABingoTerminateExperiment < R '/abingo/terminate'\n include ABingoCampingPlugin::ABingo\n include ABingoCampingPlugin::Helpers\n \n def post\n return(:abingo_dashboard) unless @input.alternative_id\n \n @alternative = ABingoCampingPlugin::Models::Alternative.find(@input.alternative_id)\n @experiment = ABingoCampingPlugin::Models::Experiment.find(@alternative.experiment_id)\n experiment_name = @experiment.test_name\n \n if (@experiment.status != \"Completed\")\n @experiment.end_experiment!(@alternative.content)\n @abingo_notice = \"Experiment '\" + experiment_name + \"' has been marked as ended. All users will now see the chosen alternative.\"\n else\n @abingo_notice = \"Experiment '\" + experiment_name + \"' is already ended.\"\n end\n \n render :abingo_termination_notice\n end\n end\n \n class ABingoRestrictedAccess < R '/abingo/restricted_access'\n def get\n render :abingo_dashboard_restricted_access\n end\n end\n\n CLASS_DEFS\nend\n" |
Instance Method Details
#include_abingo_controllers ⇒ Object
Includes the ABingo and Helpers modules inside each controller class using class_eval (this is why the call must be the last statement in the controllers module)
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 |
# File 'lib/camping-abingo.rb', line 1031 def include_abingo_controllers module_eval ABingoCampingPlugin::Controllers.common_abingo_controllers # Add ABingo to each controller by traversing @r, the list of controllers # and including the needed ABingo modules @r.each do |x| x.class_eval do include ABingoCampingPlugin::ABingo include ABingoCampingPlugin::Helpers end end end |