Last active
August 29, 2015 14:03
-
-
Save psylone/d98b55b1422257f68d66 to your computer and use it in GitHub Desktop.
Gears - the way to control your logic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support/all' | |
module Gears | |
class Base | |
private_class_method :new | |
def initialize *methods | |
attrs = methods.extract_options! | |
self.class_eval{ attr_accessor *attrs.keys } | |
attrs.each{ |attr, value| send "#{attr}=", value } | |
methods.each { |name| send name } | |
end | |
def self.perform influence, attrs | |
new *influence, attrs | |
end | |
def self.inherited subclass | |
create_storage(subclass) | |
end | |
private | |
def self.create_storage subclass | |
subclass.const_set( 'Storage', Module.new do | |
class << self | |
def set key, *values | |
unless respond_to? key | |
singleton_class.instance_eval{ attr_accessor key } | |
# TODO make different initial values dependent on their class. | |
send "#{key}=", [] | |
end | |
send(key).push *values | |
end | |
def get key | |
send(key) | |
end | |
end | |
end) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment