Module: Polecat::DocumentResource

Defined in:
lib/polecat/document_resource.rb

Instance Method Summary collapse

Instance Method Details

#create_reader_for(name) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/polecat/document_resource.rb', line 21

def create_reader_for name
  mod.module_eval <<-RUBYCODE
    def #{name.to_s}
      attribute_get :#{name}
    end
  RUBYCODE
end

#create_writer_for(name) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/polecat/document_resource.rb', line 29

def create_writer_for name
  mod.module_eval <<-RUBYCODE
    def #{name.to_s}= o
      attribute_set :#{name}, o
    end
  RUBYCODE
end

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



3
4
5
6
7
8
9
# File 'lib/polecat/document_resource.rb', line 3

def field name, options = {}
  attributes = self.instance_variable_get :@attributes
  attributes[name.to_sym] = Document::OPTIONS.merge(options)

  create_reader_for name
  create_writer_for name
end

#modObject



11
12
13
14
15
16
17
18
19
# File 'lib/polecat/document_resource.rb', line 11

def mod
  if !@mod
    @mod = Module.new
    self.class_eval do
      include @mod
    end
  end
  @mod
end