Class: RideTheStreetcar::JS

Inherits:
Object
  • Object
show all
Includes:
Streamlined::Renderable
Defined in:
lib/ride_the_streetcar/js.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJS

Returns a new instance of JS.



10
11
12
13
# File 'lib/ride_the_streetcar/js.rb', line 10

def initialize
  @chain = []
  @args = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

rubocop:disable Style/MissingRespondToMissing



15
16
17
18
19
20
# File 'lib/ride_the_streetcar/js.rb', line 15

def method_missing(method_name, *args) # rubocop:disable Style/MissingRespondToMissing
  @args = args if args.length.positive?

  chain << method_name
  self
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



8
9
10
# File 'lib/ride_the_streetcar/js.rb', line 8

def args
  @args
end

#chainObject (readonly)

Returns the value of attribute chain.



6
7
8
# File 'lib/ride_the_streetcar/js.rb', line 6

def chain
  @chain
end

Instance Method Details

#set_property?Boolean

Returns:

  • (Boolean)


22
# File 'lib/ride_the_streetcar/js.rb', line 22

def set_property? = chain.last.end_with?("=")

#templateObject



28
29
30
31
32
33
34
# File 'lib/ride_the_streetcar/js.rb', line 28

def template
  if set_property?
    render SetProperty.new(to_s, args.first)
  else
    render Apply.new(to_s, *args)
  end
end

#to_sObject



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

def to_s
  chain.join(".").delete_suffix("=")
end