Module: Bagman::Document::ClassMethods

Defined in:
lib/bagman/document.rb

Instance Method Summary collapse

Instance Method Details

#__super_bagObject



155
156
157
# File 'lib/bagman/document.rb', line 155

def __super_bag
  superclass.bag if superclass.respond_to?(:bag)
end

#bag(&blk) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/bagman/document.rb', line 138

def bag(&blk)
  if block_given?
    @bagman_has_no_bag = false
    @bag = Bag.new(self, &blk)
  else
    unless @bag
      @bag = __super_bag
      @bagman_has_no_bag = ! @bag
    end

    raise "no bag defined" if @bagman_has_no_bag

    @bag
  end
end

#bag_field(name) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/bagman/document.rb', line 160

def bag_field(name)
  class_eval <<-EOMETHOD
    def #{name}=(value)
      bag["#{name}"] = value
    end

    def #{name}
      bag["#{name}"]
    end
  EOMETHOD
end