aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-07-02 16:19:35 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-07-12 19:17:19 +0200
commit0d88de6e77c3e00398d152cd430a617b80f4c821 (patch)
tree6c282ff4c1b49d6ca26baf6ea8389a60c6a2387c /lib
parentUsers can view descriptions of question groups (diff)
downloadrecruiting-webapp-0d88de6e77c3e00398d152cd430a617b80f4c821.tar.gz
recruiting-webapp-0d88de6e77c3e00398d152cd430a617b80f4c821.tar.bz2
recruiting-webapp-0d88de6e77c3e00398d152cd430a617b80f4c821.zip
Multiple choice questions
Diffstat (limited to 'lib')
-rw-r--r--lib/permissions/inherit.rb8
-rw-r--r--lib/rich_types/check_list.rb59
2 files changed, 67 insertions, 0 deletions
diff --git a/lib/permissions/inherit.rb b/lib/permissions/inherit.rb
new file mode 100644
index 0000000..fa35a0a
--- /dev/null
+++ b/lib/permissions/inherit.rb
@@ -0,0 +1,8 @@
+require 'permissions/set.rb'
+def inherit_permissions(source)
+ one_permission(:view){ send(source).nil? || send(source).send("viewable_by?", acting_user)}
+ one_permission(:create){ send(source).nil? || send(source).send("creatable_by?", acting_user)}
+ one_permission(:update){ send(source).nil? || send(source).send("updatable_by?", acting_user)}
+ one_permission(:destroy){ send(source).nil? || send(source).send("destroyable_by?", acting_user)}
+ one_permission(:edit){ send(source).nil? || send(source).send("editable_by?", acting_user)}
+end
diff --git a/lib/rich_types/check_list.rb b/lib/rich_types/check_list.rb
new file mode 100644
index 0000000..7605d62
--- /dev/null
+++ b/lib/rich_types/check_list.rb
@@ -0,0 +1,59 @@
+module RichTypes
+ # Stores information on which options were selected.
+ # Use options and options= methods to access & set information on which are selected.
+ # Options are set on object creation time.
+ class CheckList
+ # initialize options list
+ def initialize(options)
+ @opt_list = CheckList.get_opts(options)
+ end
+
+ # return hash.
+ # result[option.id] = {:checked => Boolean, :content => String, :id => Integer}
+ def options
+ @opt_list
+ end
+
+ # Accepts Arrays (containing id's of checked options),
+ # Hashes (indexed with option.ids, each item is hash with Boolean :checked, String :content, Integer :id))
+ # and Strings (coma-separated list of id's of checked options)
+ # does *NOT* validate.
+ def options=(what)
+ klass = what.class
+
+ if klass == Hash
+ @opt_list = what
+
+ elsif klass == Array
+ for i in @opt_list.keys
+ @opt_list[i][:checked] = what.include?(i)
+ end
+
+ elsif klass == String
+ # Convert to Array and use = for Arrays
+ self.options = what.split(',').inject(Array.new){|r, c| r.push c.to_i}
+
+ elsif klass == NilClass
+ for i in @opt_list.keys
+ @opt_list[i][:checked] = false
+ end
+ end
+ end
+
+ def to_s
+ result = ""
+ for i in @opt_list.keys
+ result += i.to_s + "," if @opt_list[i][:checked]
+ end
+ result.chop
+ end
+
+ protected
+ def self.get_opts(options)
+ options.inject(Hash.new) do |result, opt|
+ result[opt.id] = {:checked => false, :content => opt.content, :id => opt.id}
+ result
+ end
+ end
+ end
+end