lib/vedeu/models/line.rb in vedeu-0.1.12 vs lib/vedeu/models/line.rb in vedeu-0.1.13
- old
+ new
@@ -1,13 +1,23 @@
module Vedeu
class Line
- def initialize(attributes = {})
+ def self.build(attributes = {}, &block)
+ new(attributes, &block).attributes
+ end
+
+ def initialize(attributes = {}, &block)
@attributes = attributes
+
+ if block_given?
+ @self_before_instance_eval = eval('self', block.binding)
+
+ instance_eval(&block)
+ end
end
def attributes
- defaults.merge!(@attributes)
+ @_attributes ||= defaults.merge!(@attributes)
end
def colour
@colour ||= Colour.new(attributes[:colour])
end
@@ -28,10 +38,14 @@
def defaults
{
colour: {},
streams: [],
- style: ''
+ style: []
}
+ end
+
+ def method_missing(method, *args, &block)
+ @self_before_instance_eval.send(method, *args, &block)
end
end
end