Class: Less::Interaction
- Inherits:
-
Object
- Object
- Less::Interaction
- Defined in:
- lib/version.rb,
lib/less_interactions/interaction.rb
Constant Summary collapse
- VERSION =
"0.2.0"
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
-
.expects(*parameters) ⇒ Object
Expect certain parameters to be present.
- .expects_any(*parameters) ⇒ Object
-
.returns(*args) ⇒ Object
Make an attr_accessor alias for what you are expecting to be returned Need to return self in the run method for to use this.
-
.run(context = {}, params = {}) ⇒ Object
Run your interaction.
Instance Method Summary collapse
- #init ⇒ Object
-
#initialize(context = {}, options = {}) ⇒ Interaction
constructor
Initialize the objects for an interaction.
-
#run ⇒ Object
Definition of the interaction itself.
Constructor Details
#initialize(context = {}, options = {}) ⇒ Interaction
Initialize the objects for an interaction.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/less_interactions/interaction.rb', line 6 def initialize(context = {}, = {}) #the param context = {} is to allow for interactions with no context if context.is_a? Hash .merge! context #context is not a Context so merge it in else [:context] = context # add context to the options so will get the ivar and getter end self.all_params = set_instance_variables .each do |name, value| if respond_to?( "#{name}=" ) send "#{name}=", value end end end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
23 24 25 |
# File 'lib/less_interactions/interaction.rb', line 23 def context @context end |
Class Method Details
.expects(*parameters) ⇒ Object .expects(*parameters, options) ⇒ Object
Expect certain parameters to be present. If any parameter can’t be found, a MissingParameterError will be raised.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/less_interactions/interaction.rb', line 55 def self.expects(*parameters) if parameters.last.is_a?(Hash) = parameters.pop else = {} end parameters.each do |parameter| add_reader(parameter) add_expectation(parameter, ) end end |
.expects_any(*parameters) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/less_interactions/interaction.rb', line 68 def self.expects_any *parameters parameters.each do |parameter| add_reader(parameter) end add_any_expectation(parameters) end |
.returns(*args) ⇒ Object
Make an attr_accessor alias for what you are expecting to be returned Need to return self in the run method for to use this
77 78 79 |
# File 'lib/less_interactions/interaction.rb', line 77 def self.returns(*args) attr_accessor(*args) end |
.run(context = {}, params = {}) ⇒ Object
Run your interaction. This will initialize your interaction with the params you pass to it and then call its #run method.
40 41 42 43 44 45 |
# File 'lib/less_interactions/interaction.rb', line 40 def self.run(context = {}, params = {}) me = new(context, params) me.send :expectations_met? me.init me.run end |
Instance Method Details
#init ⇒ Object
32 33 |
# File 'lib/less_interactions/interaction.rb', line 32 def init end |
#run ⇒ Object
Definition of the interaction itself. You should override this in your interactions
The default implementation raises an Less::InvalidInteractionError
28 29 30 |
# File 'lib/less_interactions/interaction.rb', line 28 def run raise InvalidInteractionError, "You must override the run instance method in #{self.class}" end |