Sha256: 0efa148a421d64f2c78581cd7c80c3fa93ae0b26f622eff8b8a38436f9d6b6d5
Contents?: true
Size: 1.29 KB
Versions: 12
Compression:
Stored size: 1.29 KB
Contents
module Sprinkle module Attributes extend ActiveSupport::Concern included do attr_accessor :delivery end def defaults(deployment) defaults = deployment.defaults[self.class.name.split(/::/).last.downcase.to_sym] self.set_defaults(&defaults) if defaults @delivery = deployment.style end def set_defaults(&block) before = @options @options = {} self.instance_eval(&block) if block @options = before.reverse_merge(@options) end private def read_from_package(m) @package.send(m) if @package.respond_to?(m) and @package.method(m).arity.abs < 2 end def option?(sym) !!@options[sym] end module ClassMethods def attributes(*list) list.each do |a| define_method a do |*val| val=nil if val.empty? val ? @options[a] = val.first : @options[a] || read_from_package(a) end end end def multi_attributes(*list) list.each do |a| define_method a do |*val| val = val.try(:first) return @options[a] unless val @options[a]||=[] val.is_a?(Array) ? @options[a] += val : @options[a] << val end end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems