Module: HasStimulusAttrs::ClassMethods

Defined in:
lib/has_stimulus_attrs.rb

Instance Method Summary collapse

Instance Method Details

#controller_nameObject

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/has_stimulus_attrs.rb', line 24

def controller_name
  raise NotImplementedError
end

#has_stimulus_action(event, action, controller: nil, **options) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/has_stimulus_attrs.rb', line 35

def has_stimulus_action(event, action, controller: nil, **options)
  key = :action
  val = -> {
    c = controller.is_a?(Proc) ? instance_exec(&controller) : controller
    a = case action
    when Proc then instance_exec(&action)
    else action.to_s
    end
    stimulus_action((c || controller_name), event, a).values.first
  }

  prepend___has_stimulus___method(key, val, **options)
end

#has_stimulus_class(name, value, controller: nil, **options) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/has_stimulus_attrs.rb', line 49

def has_stimulus_class(name, value, controller: nil, **options)
  key = -> {
    c = controller.is_a?(Proc) ? instance_exec(&controller) : controller
    stimulus_class((c || controller_name), name, "N/A").keys.first
  }
  val = -> {
    c = controller.is_a?(Proc) ? instance_exec(&controller) : controller
    v = case value
    when Proc then instance_exec(&value)
    else value.to_s
    end
    stimulus_class((c || controller_name), name, v).values.first
  }

  prepend___has_stimulus___method(key, val, **options)
end

#has_stimulus_controller(name = controller_name, **options) ⇒ Object



28
29
30
31
32
33
# File 'lib/has_stimulus_attrs.rb', line 28

def has_stimulus_controller(name = controller_name, **options)
  key = :controller
  val = name

  prepend___has_stimulus___method(key, val, **options)
end

#has_stimulus_outlet(name, value, controller: nil, **options) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/has_stimulus_attrs.rb', line 66

def has_stimulus_outlet(name, value, controller: nil, **options)
  key = -> {
    c = controller.is_a?(Proc) ? instance_exec(&controller) : controller
    stimulus_outlet((c || controller_name), name, "N/A").keys.first
  }
  val = -> {
    c = controller.is_a?(Proc) ? instance_exec(&controller) : controller
    v = case value
    when Proc then instance_exec(&value)
    when Symbol then send(value)
    else value
    end
    stimulus_outlet((c || controller_name), name, v).values.first
  }

  prepend___has_stimulus___method(key, val, **options)
end

#has_stimulus_param(name, value, controller: nil, **options) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/has_stimulus_attrs.rb', line 84

def has_stimulus_param(name, value, controller: nil, **options)
  key = -> {
    c = controller.is_a?(Proc) ? instance_exec(&controller) : controller
    stimulus_param((c || controller_name), name, "N/A").keys.first
  }
  val = -> {
    c = controller.is_a?(Proc) ? instance_exec(&controller) : controller
    v = case value
    when Proc then instance_exec(&value)
    when Symbol then send(value)
    else value
    end
    stimulus_param((c || controller_name), name, v).values.first
  }

  prepend___has_stimulus___method(key, val, **options)
end

#has_stimulus_target(name, controller: nil, **options) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/has_stimulus_attrs.rb', line 102

def has_stimulus_target(name, controller: nil, **options)
  key = -> {
    c = controller.is_a?(Proc) ? instance_exec(&controller) : controller
    stimulus_target((c || controller_name), name).keys.first
  }
  val = -> {
    c = controller.is_a?(Proc) ? instance_exec(&controller) : controller
    stimulus_target((c || controller_name), name).values.first
  }

  prepend___has_stimulus___method(key, val, **options)
end

#has_stimulus_value(name, value = nil, controller: nil, **options) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/has_stimulus_attrs.rb', line 115

def has_stimulus_value(name, value = nil, controller: nil, **options)
  key = -> {
    c = controller.is_a?(Proc) ? instance_exec(&controller) : controller
    stimulus_value((c || controller_name), name, "N/A").keys.first
  }
  val = -> {
    c = controller.is_a?(Proc) ? instance_exec(&controller) : controller
    v = case value
    when Proc then instance_exec(&value)
    when Symbol then send(value)
    when NilClass then send(name)
    else value
    end
    stimulus_value((c || controller_name), name, v).values.first
  }

  prepend___has_stimulus___method(key, val, **options)
end