Class: SimpleMaster::Master::Column::BitmaskColumn
- Inherits:
-
SimpleMaster::Master::Column
- Object
- SimpleMaster::Master::Column
- SimpleMaster::Master::Column::BitmaskColumn
- Defined in:
- lib/simple_master/master/column/bitmask_column.rb
Instance Attribute Summary collapse
-
#bitmask ⇒ Object
readonly
Returns the value of attribute bitmask.
-
#const_name ⇒ Object
readonly
Returns the value of attribute const_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from SimpleMaster::Master::Column
Instance Method Summary collapse
- #init(master_class, for_test = false) ⇒ Object
-
#initialize(name, options) ⇒ BitmaskColumn
constructor
A new instance of BitmaskColumn.
Methods inherited from SimpleMaster::Master::Column
column_type, column_types, #db_column_name, inherited, register
Constructor Details
#initialize(name, options) ⇒ BitmaskColumn
Returns a new instance of BitmaskColumn.
11 12 13 14 15 16 |
# File 'lib/simple_master/master/column/bitmask_column.rb', line 11 def initialize(name, ) @bitmask = [:bitmask] @const_name = "BITMASK_FOR_#{name.upcase}" super end |
Instance Attribute Details
#bitmask ⇒ Object (readonly)
Returns the value of attribute bitmask.
8 9 10 |
# File 'lib/simple_master/master/column/bitmask_column.rb', line 8 def bitmask @bitmask end |
#const_name ⇒ Object (readonly)
Returns the value of attribute const_name.
9 10 11 |
# File 'lib/simple_master/master/column/bitmask_column.rb', line 9 def const_name @const_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/simple_master/master/column/bitmask_column.rb', line 7 def name @name end |
Instance Method Details
#init(master_class, for_test = false) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/simple_master/master/column/bitmask_column.rb', line 18 def init(master_class, for_test = false) super master_class.simple_master_module.const_set(const_name, bitmask) unless master_class.const_defined?(const_name) master_class.simple_master_module.class_eval " def \#{name}\n return EMPTY_ARRAY if @\#{name}.nil?\n \#{const_name}.filter_map.with_index {\n _1 if (1 << _2) & @\#{name} != 0\n }\n end\n\n def \#{name}_value\n @\#{name}\n end\n\n def \#{name}_value=(value)\n \#{code_for_dirty_check if for_test}\n @\#{name} = value&.to_i\n end\n RUBY\nend\n", __FILE__, __LINE__ + 1 |