Module: Sprinkle::Attributes::ClassMethods

Defined in:
lib/sprinkle/extensions/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attributes(*list) ⇒ Object


34
35
36
37
38
39
40
41
# File 'lib/sprinkle/extensions/attributes.rb', line 34

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

#multi_attributes(*list) ⇒ Object


43
44
45
46
47
48
49
50
51
52
# File 'lib/sprinkle/extensions/attributes.rb', line 43

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