Project

phenomenal

0.0
No commit activity in last 3 years
No release in over 3 years
A context oriented programming framework for Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.5
 Project Readme

Phenomenal Gem Build Status Code Climate

The Phenomenal Gem is a COP framework for the dynamic programming language Ruby. With this framework, programmers can handle contexts as first-class entities allowing them to adapt the behaviour of their applications dynamically in a clean and structured manner.

See our website for more details.

Requirements

From rubygems

gem install phenomenal
require "phenomenal"

From sources

git clone https://github.com/phenomenal/phenomenal.git
require "path_to_phenomenal/lib/phenomenal.rb"

Examples

Base class

class Foo
  def initialize
    @inst_var = "bar"
  end
  def my_instance_method
    "Base instance(#{@inst_var})"
  end
  def self.my_class_method
    "Base class : #{self.name}"
  end
end

Basic example (examples/example_basic.rb)

require "phenomenal"
require "./Foo"

context :demo do 
  adaptations_for Foo
  adapt :my_instance_method do
    "Adapted instance+#{proceed}"
  end
  adapt_class :my_class_method do
    "Adapted class+#{proceed}"
  end
end

f = Foo.new
puts "===> Default behaviour"
puts f.my_instance_method (Output: "Base instance(bar)")
puts Foo.my_class_method  (Output: "Base class : Foo")

puts "===> :demo context activated"
activate_context(:demo)   
puts f.my_instance_method (Output: "Adapted instance+Base instance(bar)")
puts Foo.my_class_method  (Output: "Adapted class+Base class : Foo")

puts "===> :demo context deactivated"
deactivate_context(:demo)
puts f.my_instance_method (Output: "Base instance(bar)")
puts Foo.my_class_method  (Output: "Base class : Foo")
  • context :demo defines/reopen the context called "demo". The block contains all the adaptations specific to this context
  • adapt :my_instance_method replaces the behaviour of the instance method called "my_instance_method". The block specifies the new behaviour of the method.
  • adapt_class :my_class_method replaces the behaviour of the instance method called "my_class_method". The block specifies the new behaviour of the method.
  • activate_context(:demo) activates the context "demo" which replaces the default behaviour by the one defined in the "demo" context.
  • deactivate_context(:demo) deactivates the context "demo" which replaces the behaviour defined by the context "demo" by the default one.

Advanced example

See "examples/example_basic.rb" for more advanced examples with combined contexts, features and relationships. All our DSL is detailed here.

Contributions

If you want to contribute, please:

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is very important.
  • Send a pull request on Github with a clear description.

Tests are executed with

rake        

Copyright

Copyright (c) 2011-2012 Loïc Vigneron - Thibault Poncelet. See LICENSE for details.