Module: ActiveFile::ClassMethods
- Defined in:
- lib/active_file.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'lib/active_file.rb', line 55
def method_missing(name, *args, &block)
field = name.to_s.split("_").last
super if @fields.include? field
load_all.select do |object|
object.send(field) == args.first
end
end
|
Instance Method Details
#field(name) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/active_file.rb', line 26
def field(name)
@fields ||= []
@fields << name
get = %Q{
def #{name}
@#{name}
end
}
set = %Q{
def #{name}=(valor)
@#{name}=valor
end
}
self.class_eval get
self.class_eval set
end
|
#find(id) ⇒ Object
46
47
48
49
|
# File 'lib/active_file.rb', line 46
def find(id)
raise DocumentNotFound, "Arquivo db/revistas/#{id} nao encontrado.", caller unless File.exists?("db/revistas/#{id}.yml")
deserialize "db/revistas/#{id}.yml"
end
|
#next_id ⇒ Object
51
52
53
|
# File 'lib/active_file.rb', line 51
def next_id
Dir.glob("db/revistas/*.yml").size + 1
end
|