class Megam::MarketPlaceCollection
Attributes
iterator[R]
Public Class Methods
json_create(o)
click to toggle source
# File lib/megam/core/marketplace_collection.rb, line 101 def self.json_create(o) collection = self.new() o["results"].each do |apps_list| apps_array = apps_list.kind_of?(Array) ? apps_list : [ apps_list ] apps_array.each do |app| collection.insert(app) end end collection end
new()
click to toggle source
# File lib/megam/core/marketplace_collection.rb, line 6 def initialize @apps = Array.new @apps_by_name = Hash.new @insert_after_idx = nil end
Public Instance Methods
<<(*args)
click to toggle source
# File lib/megam/core/marketplace_collection.rb, line 26 def <<(*args) args.flatten.each do |a| is_megam_app(a) @apps << a @apps_by_name[a.flavor] = @apps.length - 1 end self end
Also aliased as: push
[](index)
click to toggle source
# File lib/megam/core/marketplace_collection.rb, line 16 def [](index) @apps[index] end
[]=(index, arg)
click to toggle source
# File lib/megam/core/marketplace_collection.rb, line 20 def []=(index, arg) is_megam_app(arg) @apps[index] = arg @apps_by_name[arg.flavor] = index end
all_apps()
click to toggle source
# File lib/megam/core/marketplace_collection.rb, line 12 def all_apps @apps end
each() { |app| ... }
click to toggle source
# File lib/megam/core/marketplace_collection.rb, line 57 def each @apps.each do |app| yield app end end
each_index() { |i| ... }
click to toggle source
# File lib/megam/core/marketplace_collection.rb, line 63 def each_index @apps.each_index do |i| yield i end end
empty?()
click to toggle source
# File lib/megam/core/marketplace_collection.rb, line 69 def empty? @apps.empty? end
for_json()
click to toggle source
# File lib/megam/core/marketplace_collection.rb, line 93 def for_json to_a.map { |item| item.to_s } end
insert(app)
click to toggle source
# File lib/megam/core/marketplace_collection.rb, line 38 def insert(app) is_megam_app(app) if @insert_after_idx # in the middle of executing a run, so any nodes inserted now should # be placed after the most recent addition done by the currently executing # node @apps.insert(@insert_after_idx + 1, app) # update name -> location mappings and register new node @apps_by_name.each_key do |key| @apps_by_name[key] += 1 if @apps_by_name[key] > @insert_after_idx end @apps_by_name[app.flavor] = @insert_after_idx + 1 @insert_after_idx += 1 else @apps << app @apps_by_name[app.flavor] = @apps.length - 1 end end
lookup(app)
click to toggle source
# File lib/megam/core/marketplace_collection.rb, line 73 def lookup(app) lookup_by = nil if app.kind_of?(Megam::MarketPlace) lookup_by = app.flavor elsif app.kind_of?(String) lookup_by = app else raise ArgumentError, "Must pass a Megam::MarketPlace or String to lookup" end res = @apps_by_name[lookup_by] unless res raise ArgumentError, "Cannot find a app matching #{lookup_by} (did you define it first?)" end @apps[res] end
to_json(*a)
click to toggle source
# File lib/megam/core/marketplace_collection.rb, line 97 def to_json(*a) Megam::JSONCompat.to_json(for_json, *a) end
to_s()
click to toggle source
# File lib/megam/core/marketplace_collection.rb, line 89 def to_s @apps.join(", ") end
Private Instance Methods
is_megam_app(arg)
click to toggle source
# File lib/megam/core/marketplace_collection.rb, line 116 def is_megam_app(arg) unless arg.kind_of?(Megam::MarketPlace) raise ArgumentError, "Members must be Megam::MarketPlace's" end true end