Module: Summon::Schema::ClassMethods

Defined in:
lib/summon/schema.rb

Instance Method Summary collapse

Instance Method Details

#attr(name, options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/summon/schema.rb', line 34

def attr(name, options = {})
  if name.to_s =~ /^(.*)\?$/
    name = $1
    options[:boolean] = true
  end
  symbol = name.to_sym
  @attrs << ::Summon::Schema::Attr.new(symbol, options)
  define_method(name) do |*args|
    self.instance_variable_get("@#{name}")  
  end
  if options[:boolean]
    define_method("#{name}?") do
      send(name)
    end
  end
end

#attrsObject



51
52
53
# File 'lib/summon/schema.rb', line 51

def attrs
  @attrs
end

#summon!Object



55
56
57
58
# File 'lib/summon/schema.rb', line 55

def summon!
  @attrs = []
  attr_reader :src
end