Module: Spider::Model::List::ClassMethods

Defined in:
lib/spiderfw/model/mixins/list.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) list(name, attributes = {})



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/spiderfw/model/mixins/list.rb', line 104

def list(name, attributes={})
    attributes[:list] = true
    attributes[:order] ||= true
    element(name, Fixnum, attributes)
    observe_element(name) do |obj, el, new_val|
        obj.save_mode do
            obj.list_mixin_modified_elements[name] = obj.get(el)
        end
    end
    
    (class << self; self; end).instance_eval do
        
        define_method("#{name}_last") do
            qs = self.all.order_by(name).limit(1)
            return qs[0]
        end
        
    end
    
    define_method("insert_last_#{name}") do
        # FIXME: locking!
        last = self.class.send("#{name}_last")
        max = last ? last.get(name) : 0
        set(name, max + 1)
    end
end

- (Object) lists



100
101
102
# File 'lib/spiderfw/model/mixins/list.rb', line 100

def lists
    elements_array.select{ |el| el.attributes[:list] }
end