Module: SimpleFlaggableColumn
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/simple_flaggable_column.rb,
lib/simple_flaggable_column/version.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
- .flags_to_symbols(flags, symbols_flags) ⇒ Object
- .symbols_to_flags(symbols, symbols_flags, throw_on_missing = true) ⇒ Object
Class Method Details
.flags_to_symbols(flags, symbols_flags) ⇒ Object
16 17 18 |
# File 'lib/simple_flaggable_column.rb', line 16 def self.flags_to_symbols(flags, symbols_flags) symbols_flags.each_pair.inject([]){|all, v| (flags & v[1] != 0) ? (all << v[0]) : all} end |
.symbols_to_flags(symbols, symbols_flags, throw_on_missing = true) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/simple_flaggable_column.rb', line 7 def self.symbols_to_flags(symbols, symbols_flags, throw_on_missing = true) symbols.map do |s| if throw_on_missing && !symbols_flags[s] throw ArgumentError.new("Flag #{s} doesn't exists") end symbols_flags[s] end.compact.reduce(:|) || 0 end |