Sha256: 539d9e21f89852c442661bf83669a50e823a7f4c15ecab56a5489237d1825b5b

Contents?: true

Size: 1.03 KB

Versions: 8

Compression:

Stored size: 1.03 KB

Contents

class StimulusReflex::ReflexFactory
  class << self
    attr_reader :reflex_data

    def create_reflex_from_data(channel, reflex_data)
      @reflex_data = reflex_data
      reflex_class.new(channel,
        url: reflex_data.url,
        element: reflex_data.element,
        selectors: reflex_data.selectors,
        method_name: reflex_data.method_name,
        params: reflex_data.form_params,
        client_attributes: {
          reflex_id: reflex_data.reflex_id,
          tab_id: reflex_data.tab_id,
          xpath_controller: reflex_data.xpath_controller,
          xpath_element: reflex_data.xpath_element,
          reflex_controller: reflex_data.reflex_controller,
          permanent_attribute_name: reflex_data.permanent_attribute_name
        })
    end

    def reflex_class
      reflex_data.reflex_name.constantize.tap { |klass| raise ArgumentError.new("#{reflex_name} is not a StimulusReflex::Reflex") unless is_reflex?(klass) }
    end

    def is_reflex?(klass)
      klass.ancestors.include? StimulusReflex::Reflex
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
stimulus_reflex-3.5.0.pre7 lib/stimulus_reflex/reflex_factory.rb
stimulus_reflex-3.5.0.pre6 lib/stimulus_reflex/reflex_factory.rb
stimulus_reflex-3.5.0.pre5 lib/stimulus_reflex/reflex_factory.rb
stimulus_reflex-3.5.0.pre4 lib/stimulus_reflex/reflex_factory.rb
stimulus_reflex-3.5.0.pre3 lib/stimulus_reflex/reflex_factory.rb
stimulus_reflex-3.5.0.pre2 lib/stimulus_reflex/reflex_factory.rb
stimulus_reflex-3.5.0.pre1 lib/stimulus_reflex/reflex_factory.rb
stimulus_reflex-3.5.0.pre0 lib/stimulus_reflex/reflex_factory.rb