Class: Compass::Canvas::Backend::Interface::Base

Inherits:
Sass::Script::Literal
  • Object
show all
Defined in:
lib/canvas/backend/interface.rb

Overview

Base class for all interface classes.

This class unpacks Sass types to Ruby objects before passing them to a backend implementation.

Direct Known Subclasses

Context, Path, Pattern

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, *args) ⇒ Base

Initializes a new instance of an interface class.

Parameters:

  • action (String)

    The action to take, e.g., move, line.

  • args (Array<Sass::Script::Literal>)

    The arguments to pass.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/canvas/backend/interface.rb', line 19

def initialize(action, *args)
  @action = action.value.to_sym
  unless self.respond_to?(@action)
    recognised = self.class.public_instance_methods - self.class.superclass.public_instance_methods
    raise Compass::Canvas::Exception.new("(#{self.class}) '#{@action}' is not a recognised action. Did you mean any of the following: '#{ recognised.join("', '") }'?")
  end
  arity = self.method(@action).arity.abs
  unless args.length >= arity
    raise Compass::Canvas::Exception.new("(#{self.class}.#{@action}) Wrong number of arguments (#{args.length} for #{arity}).")
  end
  @args = self.send(@action, *args)
end

Instance Attribute Details

#actionString

Returns The action to take, e.g., move, line.

Returns:

  • (String)

    The action to take, e.g., move, line.



11
12
13
# File 'lib/canvas/backend/interface.rb', line 11

def action
  @action
end

#argsArray

Returns The arguments to pass, e.g., X and Y coordinates.

Returns:

  • (Array)

    The arguments to pass, e.g., X and Y coordinates.



13
14
15
# File 'lib/canvas/backend/interface.rb', line 13

def args
  @args
end

Instance Method Details

#to_s(options = {}) ⇒ Object

Raises:



33
34
35
# File 'lib/canvas/backend/interface.rb', line 33

def to_s(options = {})
  raise Compass::Canvas::Exception.new("(#{self.class}.#{@action}) Not available in this context.")
end