Skip to content

Commit

Permalink
Alias writer
Browse files Browse the repository at this point in the history
  • Loading branch information
antulik committed Jul 9, 2024
1 parent 02d704d commit c1a0654
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions lib/active_interaction/extras/filter_alias.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
# frozen_string_literal: true

# Add :as option, which is a read alias to filter
# hash :params, as: :account_attributes
# hash :account, as: :account_attributes
#
module ActiveInteraction::Extras::FilterAlias
extend ActiveSupport::Concern

# concern :InputsExtension do
# def normalize(inputs)
# @base.class.filters.each do |name, filter|
# alias_name = filter.options[:as]
#
# if alias_name.nil?
# next
#
# elsif inputs.key?(alias_name.to_sym)
# inputs[name.to_sym] = inputs[alias_name.to_sym]
#
# elsif inputs.key?(alias_name.to_s)
# inputs[name.to_s] = inputs[alias_name.to_s]
# end
# end
#
# super
# end
# end
#
# included do
# ActiveInteraction::Inputs.prepend InputsExtension
# end

class_methods do
def initialize_filter(filter)
super.tap do
if filter.options[:as]
alias_method filter.options[:as], filter.name
name = filter.options[:as]
alias_method name, filter.name
# alias_method "#{name}=", "#{filter.name}="
end
end
end
Expand Down

0 comments on commit c1a0654

Please sign in to comment.