Class: Vident::StimulusAttributeBase

Inherits:
Object
  • Object
show all
Defined in:
lib/vident/stimulus_attribute_base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, implied_controller: nil) ⇒ StimulusAttributeBase

Returns a new instance of StimulusAttributeBase.



21
22
23
24
# File 'lib/vident/stimulus_attribute_base.rb', line 21

def initialize(*args, implied_controller: nil)
  @implied_controller = implied_controller
  parse_arguments(*args)
end

Instance Attribute Details

#implied_controllerObject (readonly)

Returns the value of attribute implied_controller.



19
20
21
# File 'lib/vident/stimulus_attribute_base.rb', line 19

def implied_controller
  @implied_controller
end

Class Method Details

.js_name(name) ⇒ Object

‘:my_thing` → `“myThing”`



15
16
17
# File 'lib/vident/stimulus_attribute_base.rb', line 15

def self.js_name(name)
  name.to_s.camelize(:lower)
end

.stimulize_path(path) ⇒ Object

‘“admin/users”` → `“admin–users”`; accepts Symbol or String.



10
11
12
# File 'lib/vident/stimulus_attribute_base.rb', line 10

def self.stimulize_path(path)
  path.to_s.split("/").map(&:dasherize).join("--")
end

Instance Method Details

#data_attribute_nameObject

Raises:

  • (NoMethodError)


34
# File 'lib/vident/stimulus_attribute_base.rb', line 34

def data_attribute_name = raise(NoMethodError, "Subclasses must implement data_attribute_name")

#data_attribute_valueObject

Raises:

  • (NoMethodError)


36
# File 'lib/vident/stimulus_attribute_base.rb', line 36

def data_attribute_value = raise(NoMethodError, "Subclasses must implement data_attribute_value")

#implied_controller_nameObject

Raises:

  • (ArgumentError)


43
44
45
46
# File 'lib/vident/stimulus_attribute_base.rb', line 43

def implied_controller_name
  raise ArgumentError, "implied_controller is required to get implied controller name" unless implied_controller
  implied_controller.name
end

#implied_controller_pathObject

Raises:

  • (ArgumentError)


38
39
40
41
# File 'lib/vident/stimulus_attribute_base.rb', line 38

def implied_controller_path
  raise ArgumentError, "implied_controller is required to get implied controller path" unless implied_controller
  implied_controller.path
end

#inspectObject



26
# File 'lib/vident/stimulus_attribute_base.rb', line 26

def inspect = "#<#{self.class.name} #{to_h}>"

#to_hObject Also known as: to_hash



30
# File 'lib/vident/stimulus_attribute_base.rb', line 30

def to_h = {data_attribute_name => data_attribute_value}

#to_sObject

Raises:

  • (NoMethodError)


28
# File 'lib/vident/stimulus_attribute_base.rb', line 28

def to_s = raise(NoMethodError, "Subclasses must implement to_s")