lib/kaicho.rb in kaicho-0.2.2 vs lib/kaicho.rb in kaicho-0.3.0

- old
+ new

@@ -91,10 +91,11 @@ else -> { share.class_variable_get(:"@@#{dname}") } end define_singleton_method(dname) do + update_depends(dname) update_resource(dname, rand) unless resource_defined?(dname) read.call end true @@ -115,11 +116,22 @@ ->(v) { instance_variable_set(:"@#{dname}", v) } else ->(v) { share.class_variable_set(:"@@#{dname}", v) } end + read = + if share.nil? + -> { instance_variable_get(:"@#{dname}") } + else + -> { share.class_variable_get(:"@@#{dname}") } + end + define_singleton_method(:"#{dname}=") do |v| + if resource_defined?(dname) && read.call == v + return v + end + write.call(v) update_dependants(dname, rand) v end @@ -281,9 +293,12 @@ update_resource(d, udid) when :keep update_resource(d, udid) unless resource_defined?(d) when :fail return false unless resource_defined?(d) + when Proc, UnboundMethod, Method + o = o.bind(self) if o.is_a?(UnboundMethod) + update_resource(d, udid) if o.call end end true end