Class: Rhom::RhomSource

Inherits:
Object show all
Extended by:
RhomObject
Includes:
RhomObject
Defined in:
lib/rhom/rhom_source.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RhomObject

djb_hash, extract_options, method_missing, method_name_reserved?, remove_var, strip_braces

Constructor Details

#initialize(args, count = 0) ⇒ RhomSource

Returns a new instance of RhomSource.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rhom/rhom_source.rb', line 12

def initialize(args,count=0)
  # setup the name
  # TODO: should really store this in the database
  Rho::RhoConfig::sources.each do |key,value|
    if value['source_id'].to_i == args['source_id'].to_i
      @name = key
    end
  end
  @source_id = args['source_id'].to_i
  @source_url = args['source_url']
  @last_updated = Time.at(args['last_updated'].to_i).to_s
  @last_inserted_size = args['last_inserted_size'].to_i
  @last_deleted_size = args['last_deleted_size'].to_i
  @last_sync_duration = args['last_sync_duration'].to_i
  @last_sync_success = args['last_sync_success'].to_i == 1 ? true : false
  @distinct_objects = ::Rhom::RhomDbAdapter::select_from_table(
                                                         ::Rhom::TABLE_NAME,
                                                         'object',
                                                         {"source_id"=>@source_id},
                                                         {"distinct"=>true}).length
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rhom::RhomObject

Instance Attribute Details

#distinct_objectsObject (readonly)

Returns the value of attribute distinct_objects.



8
9
10
# File 'lib/rhom/rhom_source.rb', line 8

def distinct_objects
  @distinct_objects
end

#last_deleted_sizeObject (readonly)

Returns the value of attribute last_deleted_size.



8
9
10
# File 'lib/rhom/rhom_source.rb', line 8

def last_deleted_size
  @last_deleted_size
end

#last_inserted_sizeObject (readonly)

Returns the value of attribute last_inserted_size.



8
9
10
# File 'lib/rhom/rhom_source.rb', line 8

def last_inserted_size
  @last_inserted_size
end

#last_sync_durationObject (readonly)

Returns the value of attribute last_sync_duration.



8
9
10
# File 'lib/rhom/rhom_source.rb', line 8

def last_sync_duration
  @last_sync_duration
end

#last_sync_successObject (readonly)

Returns the value of attribute last_sync_success.



8
9
10
# File 'lib/rhom/rhom_source.rb', line 8

def last_sync_success
  @last_sync_success
end

#last_updatedObject (readonly)

Returns the value of attribute last_updated.



8
9
10
# File 'lib/rhom/rhom_source.rb', line 8

def last_updated
  @last_updated
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/rhom/rhom_source.rb', line 8

def name
  @name
end

#source_idObject (readonly)

Returns the value of attribute source_id.



8
9
10
# File 'lib/rhom/rhom_source.rb', line 8

def source_id
  @source_id
end

#source_urlObject

Returns the value of attribute source_url.



7
8
9
# File 'lib/rhom/rhom_source.rb', line 7

def source_url
  @source_url
end

Class Method Details

.find(*args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rhom/rhom_source.rb', line 36

def find(*args)
  list = []
  if args.first == :all
    results = ::Rhom::RhomDbAdapter::select_from_table('sources', '*')
    
    results.each do |result|
      list << RhomSource.new(result)
    end
  else
    result = ::Rhom::RhomDbAdapter::select_from_table('sources', '*', 
                                                      {"source_id" => strip_braces(args.first)}).first
    list << RhomSource.new(result)
  end
  list.size > 1 ? list : list[0]
end

Instance Method Details

#update_attributes(params = nil) ⇒ Object



53
54
55
56
57
58
# File 'lib/rhom/rhom_source.rb', line 53

def update_attributes(params=nil)
  if params
    ::Rhom::RhomDbAdapter::update_into_table('sources', {"source_url"=>params['source_url']},
                                             {"source_id"=>strip_braces(params['source_id'])})
  end
end