Module: Aclatraz::Helpers
- Included in:
- Aclatraz, Store::Cassandra, Store::Mongo, Store::Redis, Store::Riak
- Defined in:
- lib/aclatraz/helpers.rb
Instance Method Summary collapse
-
#camelize(str) ⇒ Object
Given underscored word, returns camelized version of it.
-
#pack(role, object = nil) ⇒ Object
Pack given permission data.
-
#suspect_id(suspect) ⇒ Object
If given object is kind of string or integer then returns it, otherwise it tries to return its ID.
-
#unpack(data) ⇒ Object
Unpack given permission data.
Instance Method Details
#camelize(str) ⇒ Object
Given underscored word, returns camelized version of it.
camelize() # => "FooBarBla"
6 7 8 |
# File 'lib/aclatraz/helpers.rb', line 6 def camelize(str) str.split('_').map {|w| w.capitalize}.join end |
#pack(role, object = nil) ⇒ Object
Pack given permission data.
pack(foo) # => "foo"
pack(foo, "FooClass") # => "foo/FooClass"
pack(foo, FooClass.new) # => "foo/FooClass/{foo_object_ID}"
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/aclatraz/helpers.rb', line 26 def pack(role, object=nil) case object when nil [role] when Class [role, object.name] else [role, object.class.name, object.id] end.join("/") end |
#suspect_id(suspect) ⇒ Object
If given object is kind of string or integer then returns it, otherwise it tries to return its ID.
12 13 14 |
# File 'lib/aclatraz/helpers.rb', line 12 def suspect_id(suspect) suspect.is_a?(String) || suspect.is_a?(Integer) ? suspect.to_s : suspect.id.to_s end |
#unpack(data) ⇒ Object
Unpack given permission data.
17 18 19 |
# File 'lib/aclatraz/helpers.rb', line 17 def unpack(data) data.to_s.split("/") end |