Class: Decidim::Voca::Rpc::EnumCaster
- Inherits:
-
Object
- Object
- Decidim::Voca::Rpc::EnumCaster
- Defined in:
- app/rpc/decidim/voca/rpc/enum_casting.rb
Instance Attribute Summary collapse
-
#decidim_rpc_mapping ⇒ Object
readonly
Returns the value of attribute decidim_rpc_mapping.
-
#symbolic_mapping ⇒ Object
readonly
Returns the value of attribute symbolic_mapping.
Instance Method Summary collapse
- #decidim_to_rpc(decidim_key) ⇒ Object
-
#initialize(enum_module, decidim_rpc_mapping) ⇒ EnumCaster
constructor
A new instance of EnumCaster.
- #rpc_to_decidim(rpc_symbol) ⇒ Object
Constructor Details
#initialize(enum_module, decidim_rpc_mapping) ⇒ EnumCaster
Returns a new instance of EnumCaster.
6 7 8 9 |
# File 'app/rpc/decidim/voca/rpc/enum_casting.rb', line 6 def initialize(enum_module, decidim_rpc_mapping) @decidim_rpc_mapping = decidim_rpc_mapping.deep_symbolize_keys @symbolic_mapping = Hash[enum_module.descriptor.collect { |i| [i, enum_module.resolve(i)] }] end |
Instance Attribute Details
#decidim_rpc_mapping ⇒ Object (readonly)
Returns the value of attribute decidim_rpc_mapping.
5 6 7 |
# File 'app/rpc/decidim/voca/rpc/enum_casting.rb', line 5 def decidim_rpc_mapping @decidim_rpc_mapping end |
#symbolic_mapping ⇒ Object (readonly)
Returns the value of attribute symbolic_mapping.
5 6 7 |
# File 'app/rpc/decidim/voca/rpc/enum_casting.rb', line 5 def symbolic_mapping @symbolic_mapping end |
Instance Method Details
#decidim_to_rpc(decidim_key) ⇒ Object
11 12 13 14 |
# File 'app/rpc/decidim/voca/rpc/enum_casting.rb', line 11 def decidim_to_rpc(decidim_key) matches = decidim_rpc_mapping.find { |k, _v| k === decidim_key.to_sym } (matches || []).last end |
#rpc_to_decidim(rpc_symbol) ⇒ Object
16 17 18 19 20 |
# File 'app/rpc/decidim/voca/rpc/enum_casting.rb', line 16 def rpc_to_decidim(rpc_symbol) rpc_value = symbolic_mapping[rpc_symbol] matches = decidim_rpc_mapping.find { |_k, v| v === rpc_value } (matches || []).first end |