Rspec Screenshot

Rspec Screenshot
Copyright © 2014, 2015 LHA. All rights reserved.

Wednesday, January 21, 2015

Injector Orthogonality

In this release we have primarily relegated code in the examples name space to a second plane. It is assumed that if you want to run those examples you will know to enable them in the spec_helper, and that you will have the debugger appropriate for version of Ruby present on your machine as we have eliminated the dependencies.

We have also started a new set of examples on injectors that illustrate some additional properties of injectors we have cataloged under the description of orthogonality. They are intended to do just that, show some of the orthogonality available to injectors with respect to the rest of the library.

In this example we illustrate the various alternate and equivalent ways of working with Injector and member method declarations. Take a look:


class SomeClass
end

injector :Function do
   def meth
   end
end
SomeClass.inject Function()
# ...
SomeClass.eject Function() 



injector :Function
SomeClass.inject Function() do
   def meth
   end
end

# ...
SomeClass.eject Function() 




SomeClass.inject facet :Function do
   def meth
   end
end

# ...
SomeClass.eject Function() 

In this example we show how injectors like other mix-ins can be self extended/enriched, and they can under the right premises also be made to work in conjunction with #decorate and #with.


injector :tester 
                      
tester do                      
   enrich self          
                      
   def meth arg         
      arg * arg
   end
end
tester.meth(4).should == 16  


tester do
   decorate :meth do |arg|    
      super(arg) + 1
   end
end
tester.meth(3).should == 10  

with tester do         
   meth(5).should == 26
   def math arg1, arg2      
      meth(arg1 + arg2)
   end
end
tester.math(3, 2).should == 26 
  

A few last examples before we go.


class SomeClass
end

injector :Ortho

with Ortho() do
   def foo
   end
end

SomeClass.inject Ortho()

# ...


      

   
   

with SomeClass do
   include Ortho()
   extend Ortho(), Ortho()
end
     
# ....

with SomeClass do
   eject *injectors
end
      

  



with Ortho() do
   lets(:brand){'Special Brand'}

   def print
      puts brand
   end
end

enrich Ortho()
make.should == 'Special Brand'
#...
  

We hope you find the code illustrative, and please continue to send your comments and inquiries to the address on Github. We will do our best to answer them as quickly and knowledgeably as we can. Remember that some of this is uncharted territory and we are kind of making it up as we go.

Thanks so much for the people that have show interest, and kind regards to all.


lha

No comments:

Post a Comment