Class: ScheduledResource

Inherits:
Object
  • Object
show all
Defined in:
lib/scheduled_resource.rb,
lib/scheduled_resource/helper.rb,
lib/scheduled_resource/version.rb,
lib/scheduled_resource/resource_use_block.rb

Overview

Using ScheduledResource as a module here for namespacing (in transition).

Defined Under Namespace

Modules: Helper Classes: ResourceUseBlock

Constant Summary collapse

CONFIG_FILE =
"config/resource_schedule.yml"
VERSION =
"0.0.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind, sub_id) ⇒ ScheduledResource

Instance methods



228
229
230
231
232
# File 'lib/scheduled_resource.rb', line 228

def initialize( kind, sub_id ) # :nodoc:
  @tag = self.class.send( :compose_tag, kind, sub_id )
  @label = @title = nil
  config[:rsrc_of_tag][@tag] = self
end

Instance Attribute Details

#labelObject

Returns the value of attribute label.



250
251
252
# File 'lib/scheduled_resource.rb', line 250

def label
  @label
end

#titleObject

Returns the value of attribute title.



250
251
252
# File 'lib/scheduled_resource.rb', line 250

def title
  @title
end

Class Method Details

.block_class_for_resource_name(name) ⇒ Object

Parameters

  • name - The class name (string) of a schedule resource.

Returns

  • Class - The class representing the use of that resource for an interval of time.



111
112
113
# File 'lib/scheduled_resource.rb', line 111

def self.block_class_for_resource_name( name )
  config[:block_class_for_resource_kind][name]
end

.config_from_yaml(session) ⇒ Object

ToDo: Generalize this so configuration can be loaded on per-user. Process configuration file.



142
143
144
145
146
# File 'lib/scheduled_resource.rb', line 142

def self.config_from_yaml( session )
  config_from_yaml1
  config_from_yaml2 session
  config
end

.ensure_config(session) ⇒ Object

– Restore configuration from session.

When we depend on data in the configuration to satisfy a query we are not being RESTful. On the other hand we are not maintaining changeable state here – it’s just a cache. If there were changeable state it would likely be kept, eg, in a per-user table in the database. ++



133
134
135
136
137
# File 'lib/scheduled_resource.rb', line 133

def self.ensure_config( session ) # :nodoc:
  return if (self.config ||= session[:schedule_config])

  config_from_yaml( session )
end

.get_all_blocks(t1, t2, inc) ⇒ Object

(SchedResource protocol) Returns a hash where each key is an rid and the value is an array of resource use blocks in the interval t1...t2, ordered by starttime.

What in means depends on inc. If inc(remental) is false, the client is building the interval from scratch. If “hi”, it is an addition to an existing interval on the high side. Similarly for “lo”. This is to avoid re-transmitting blocks that span the current time boundaries on the client.

Here the resource is a channel and the use blocks are programs.

Parameters

  • rids - A list of schedules resource ids (strings).

  • t1 - Start time.

  • t2 - End time.

  • inc - One of nil, “lo”, “hi” (See above).

Returns

  • Hash - Each key is an rid and the value is an array of resource use blocks in the interval, ordered by starttime.



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/scheduled_resource.rb', line 91

def self.get_all_blocks(t1, t2, inc)
  blockss = {}

  config[:rsrcs_by_kind].each do |kind, rsrcs|
    rub_class = block_class_for_resource_name kind
    rids      = rsrcs.map{ |r| r.sub_id }
    ru_blkss  = rub_class.get_all_blocks rids, t1, t2, inc

    add_rubs_of_kind kind, ru_blkss, blockss
  end

  blockss
end

.resource_listObject

Returns

  • Array[SchedResource] - List of all configured SchedResources .



118
# File 'lib/scheduled_resource.rb', line 118

def self.resource_list; config[:all_resources] end

.visible_timeObject

Returns

  • Time - The configured width of the visible time window.



122
# File 'lib/scheduled_resource.rb', line 122

def self.visible_time;  config[:visible_time] end

Instance Method Details

#css_classes_for_rowObject

Returns

  • String - CSS classes automatically generated for the DOM row representing this SchedResource.



261
# File 'lib/scheduled_resource.rb', line 261

def css_classes_for_row(); "rsrcRow #{self.kind}row #{@tag}row #{self.kind}Row #{@tag}Row" end

#inspectObject

:nodoc:



246
247
248
# File 'lib/scheduled_resource.rb', line 246

def inspect() # :nodoc:
  "<#SchedResource \"#{@tag}\">"
end

#kindObject

Returns

  • String - The class name of the scheduled resource.



236
# File 'lib/scheduled_resource.rb', line 236

def kind()    @tag.sub( /_.*/, '' )          end

#sub_idObject

Returns

  • String - The rid (abstract id) of the SchedResource.



240
# File 'lib/scheduled_resource.rb', line 240

def sub_id()  @tag.sub( /.*_/, '' )          end

#to_sObject

:nodoc:



242
243
244
# File 'lib/scheduled_resource.rb', line 242

def to_s() # :nodoc:
  @tag
end