Module: InertiaRails::Controller::ClassMethods
- Defined in:
- lib/inertia_rails/controller.rb
Instance Method Summary collapse
- #_inertia_configuration ⇒ Object
- #_inertia_shared_data ⇒ Object
- #inertia_config(**attrs) ⇒ Object
- #inertia_share(hash = nil, **props, &block) ⇒ Object
- #use_inertia_instance_props ⇒ Object
Instance Method Details
#_inertia_configuration ⇒ Object
50 51 52 53 54 55 |
# File 'lib/inertia_rails/controller.rb', line 50 def _inertia_configuration @_inertia_configuration ||= begin config = superclass.try(:_inertia_configuration) || ::InertiaRails.configuration @inertia_config&.with_defaults(config) || config end end |
#_inertia_shared_data ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/inertia_rails/controller.rb', line 57 def _inertia_shared_data @_inertia_shared_data ||= begin shared_data = superclass.try(:_inertia_shared_data) if @inertia_share && shared_data.present? shared_data + @inertia_share.freeze else @inertia_share || shared_data || [] end.freeze end end |
#inertia_config(**attrs) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/inertia_rails/controller.rb', line 33 def inertia_config(**attrs) config = InertiaRails::Configuration.new(**attrs) if @inertia_config @inertia_config.merge!(config) else @inertia_config = config end end |
#inertia_share(hash = nil, **props, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/inertia_rails/controller.rb', line 18 def inertia_share(hash = nil, **props, &block) = (props) return push_to_inertia_share(**(hash || props), &block) if .empty? push_to_inertia_share do next unless [:if].all? { |filter| instance_exec(&filter) } if [:if] next unless [:unless].none? { |filter| instance_exec(&filter) } if [:unless] next hash unless block res = instance_exec(&block) hash ? hash.merge(res) : res end end |
#use_inertia_instance_props ⇒ Object
43 44 45 46 47 48 |
# File 'lib/inertia_rails/controller.rb', line 43 def use_inertia_instance_props before_action do @_inertia_instance_props = true @_inertia_skip_props = view_assigns.keys + ['_inertia_skip_props'] end end |