Class: Compass::Canvas::Backend::Interface::Base
- Inherits:
-
Sass::Script::Literal
- Object
- Sass::Script::Literal
- Compass::Canvas::Backend::Interface::Base
- 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.
Instance Attribute Summary collapse
-
#action ⇒ String
The action to take, e.g.,
move
,line
. -
#args ⇒ Array
The arguments to pass, e.g.,
X
andY
coordinates.
Instance Method Summary collapse
-
#initialize(action, *args) ⇒ Base
constructor
Initializes a new instance of an interface class.
- #to_s(options = {}) ⇒ Object
Constructor Details
#initialize(action, *args) ⇒ Base
Initializes a new instance of an interface class.
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
#action ⇒ String
Returns The action to take, e.g., move
, line
.
11 12 13 |
# File 'lib/canvas/backend/interface.rb', line 11 def action @action end |
#args ⇒ Array
Returns 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
33 34 35 |
# File 'lib/canvas/backend/interface.rb', line 33 def to_s( = {}) raise Compass::Canvas::Exception.new("(#{self.class}.#{@action}) Not available in this context.") end |