Module: Fold::SliceFactory
- Included in:
- Precompiler
- Defined in:
- lib/fold/slice_factory.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#detect_slice_class(line) ⇒ Object
def produce line=” # This all happens because I need to access Precompiler attributes # from within AbstractFold render methods # Pretty much needs a nice refactor, but don’t have the time.
- #process(line = '') ⇒ Object
Class Method Details
.included(klass) ⇒ Object
3 4 5 |
# File 'lib/fold/slice_factory.rb', line 3 def self.included klass klass.extend ClassMethods end |
Instance Method Details
#detect_slice_class(line) ⇒ Object
def produce line=” # This all happens because I need to access Precompiler attributes # from within AbstractFold render methods # Pretty much needs a nice refactor, but don’t have the time. # PS: thx ruby
fold = if klass= detect_class(line)
klass.new attrs
else
AbstractFold.new attrs.merge(:tabs => -1)
end
instance_variables.each do |var|
fold.instance_variable_set var, instance_variable_get(var)
fold.metaclass.send :attr_accessor, var.gsub('@', '')
end
that = self
fold.meta_def :method_missing do |meth, *args|
return that.send(meth, *args) if that.respond_to?(meth)
super
end
fold
end
42 43 44 45 |
# File 'lib/fold/slice_factory.rb', line 42 def detect_slice_class line return nil if line.blank? self.class.defined_slices.reverse.detect {|slice| slice::Regex and slice::Regex.match(line)} end |
#process(line = '') ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/fold/slice_factory.rb', line 7 def process line='' self.class.defined_slices.each do |slice| line.gsub! slice::Regex do |match| text = $1 eval(slice::Block.to_ruby).call end end line end |