Module: Trax::Model::Mixins::StiEnum::ClassMethods
- Defined in:
- lib/trax/model/mixins/sti_enum.rb
Instance Method Summary collapse
- #kind_to_type_mapping ⇒ Object
- #subclass_from_attributes?(attrs) ⇒ Boolean
- #type_to_kind_mapping ⇒ Object
Instance Method Details
#kind_to_type_mapping ⇒ Object
40 41 42 43 44 45 |
# File 'lib/trax/model/mixins/sti_enum.rb', line 40 def kind_to_type_mapping @kind_to_type_mapping ||= fields[:kind].choices.each_with_object({}) do |choice, result| result[choice.to_s] = choice.attributes[:type] result end.with_indifferent_access end |
#subclass_from_attributes?(attrs) ⇒ Boolean
27 28 29 30 31 |
# File 'lib/trax/model/mixins/sti_enum.rb', line 27 def subclass_from_attributes?(attrs) _attrs = attrs.with_indifferent_access if attrs attrs[:type] = kind_to_type_mapping[_attrs["kind"]] if attrs && !_attrs.key?("type") && _attrs.key?("kind") super(attrs) end |
#type_to_kind_mapping ⇒ Object
33 34 35 36 37 38 |
# File 'lib/trax/model/mixins/sti_enum.rb', line 33 def type_to_kind_mapping @type_to_kind_mapping ||= fields[:kind].choices.each_with_object({}) do |choice, result| result[choice.attributes[:type]] = choice.to_s result end.with_indifferent_access end |