Sha256: 3ea90d21028871abfaccdbe83a3bb51b73481b130639b74aa6022ababba965a6
Contents?: true
Size: 1.11 KB
Versions: 37
Compression:
Stored size: 1.11 KB
Contents
module ZTK::DSL::Core # @author Zachary Patten <zachary AT jovelabs DOT com> # @api private module Attributes def self.included(base) base.class_eval do base.send(:extend, ZTK::DSL::Core::Options::ClassMethods) base.add_option(:attribute) base.send(:extend, ZTK::DSL::Core::Attributes::ClassMethods) end end def attributes @attributes ||= Hash.new end # @author Zachary Patten <zachary AT jovelabs DOT com> module ClassMethods def attribute(key, options={}) attribute_options[key] = options send(:define_method, key) do |*args| if args.count == 0 if (self.class.attribute_options[key] && self.class.attribute_options[key][:default]) attributes[key] ||= (self.class.attribute_options[key][:default].dup rescue self.class.attribute_options[key][:default]) end attributes[key] else send("#{key}=", *args) end end send(:define_method, "#{key}=") do |value| attributes[key] = value end end end end end
Version data entries
37 entries across 37 versions & 1 rubygems