Class: Spider::App::AppSpec

Inherits:
Object show all
Defined in:
lib/spiderfw/app.rb

Overview

The AppSpec class represents an app’s .spec file The AppSpec attributes are:

  • :app_id [String] sunique identifier for the app

  • :name [String] descriptive name

  • :description [String]

  • :git_repo [String] URL of git repository for the app

  • :git_repo_rw [String] URL of read/write git repository for the app

  • :authors [Array]

  • :depends [Array] Apps this app depends on

  • :depends_optional [Array] Optional dependencies

  • :load_after [Array] Apps that must be loaded before this one (if present)

  • :gems [Array] Gems this app depends on

  • :gems_optional [Array] Optional gem dependencies

  • :version [Gem::Version] Current app version

  • :app_server [String] URL for the app server of this app

  • :auto_update [TrueClass|FalseClass] true by default; set to false if this version can’t be auto-updated

Constant Summary collapse

@@attributes =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#branchObject

The git branch used for the app



440
441
442
# File 'lib/spiderfw/app.rb', line 440

def branch
  @branch
end

Class Method Details

.array_attribute(name, options = {}) ⇒ nil

Helper method to define an Array attribute on the AppSpec class



411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/spiderfw/app.rb', line 411

def self.array_attribute(name, options={})
    @@attributes << name
    str = "    def \#{name}(*vals)\n        @\#{name} = vals unless vals.empty?\n        @\#{name} ||= []\n        @\#{name}\n    end\n"
    class_eval(str)
    nil
end

.attribute(name, options = {}) ⇒ nil

Helper method to define an attribute on the AppSpec class



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/spiderfw/app.rb', line 391

def self.attribute(name, options={})
    @@attributes << name
    str = "    def \#{name}(val=nil)\n        @\#{name} = val if val\n        @\#{name} ||= \#{options[:default].inspect}\n        @\#{name}\n    end\n    alias :\#{name}= :\#{name}\n"
    if options[:default].is_a?(TrueClass) || options[:default].is_a?(FalseClass)
        str += "\nalias :#{name}? :#{name}\n"
    end
    class_eval(str)
    nil
end

.eval(text, path = nil) ⇒ AppSpec

Returns a new AppSpec instance, evaluating the given code



491
492
493
# File 'lib/spiderfw/app.rb', line 491

def self.eval(text, path=nil)
    self.new.eval(text, path)
end

.load(spec_path) ⇒ AppSpec

Returns a new AppSpec instance, loading from a .spec file



475
476
477
# File 'lib/spiderfw/app.rb', line 475

def self.load(spec_path)
    self.new.load(spec_path)
end

.parse_hash(h) ⇒ AppSpec

Constructs a new AppSpec instance from an Hash of attributes



516
517
518
519
520
521
522
523
524
525
526
# File 'lib/spiderfw/app.rb', line 516

def self.parse_hash(h)
    spec = self.new
    h.each do |key, value|
        if value.is_a?(Array)
            spec.send(:"#{key}", *value)
        else
            spec.send(:"#{key}", value)
        end
    end
    spec
end

Instance Method Details

#author(val = nil) ⇒ String

Sets or retrieves the first AppSpec author



458
459
460
461
462
# File 'lib/spiderfw/app.rb', line 458

def author(val = nil)
    @authors = [val] if val
    @authors ||= []
    @authors[0]
end

#eval(text, path = nil) ⇒ AppSpec

Evals the given code in the AppSpec’s context



482
483
484
485
# File 'lib/spiderfw/app.rb', line 482

def eval(text, path=nil)
    self.instance_eval(text)
    self
end

#gems_listArray

Returns an Array of gem names for gems this AppSpec depends on



537
538
539
# File 'lib/spiderfw/app.rb', line 537

def gems_list
    self.gems.map{ |g| g.is_a?(Array) ? g.first : g }
end

#gems_optional_listArray

Returns an Array of optional gem names



543
544
545
# File 'lib/spiderfw/app.rb', line 543

def gems_optional_list
    self.gems_optional.map{ |g| g.is_a?(Array) ? g.first : g }
end

#get_runtime_dependenciesArray

Returns an array of apps needed at runtime



530
531
532
533
# File 'lib/spiderfw/app.rb', line 530

def get_runtime_dependencies
    return self.load_after unless @load_after.blank?
    return self.depends + self.depends_optional
end

#id(val = nil) ⇒ String

Sets or retrieves the AppSpec id



444
445
446
# File 'lib/spiderfw/app.rb', line 444

def id(val=nil)
    self.app_id(val)
end

#load(spec_path) ⇒ self

Loads attributes from a .spec file



467
468
469
470
# File 'lib/spiderfw/app.rb', line 467

def load(spec_path)
    self.eval(File.read(spec_path), spec_path)
    self
end

#to_hHash

Returns all attributes as an Hash



497
498
499
500
501
502
503
504
# File 'lib/spiderfw/app.rb', line 497

def to_h
    h = {}
    @@attributes.each do |a|
        h[a] = send(a)
    end
    h[:branch] = @branch unless @branch.blank?
    h
end

#to_json(opts = nil) ⇒ String

Returns the Hash (as in #to_hash) as JSON



509
510
511
# File 'lib/spiderfw/app.rb', line 509

def to_json(opts=nil)
    to_h.to_json
end

#version(val = nil) ⇒ Gem::Version

Sets or retrieves the AppSpec version



451
452
453
454
# File 'lib/spiderfw/app.rb', line 451

def version(val=nil)
    @version = Gem::Version.new(val) if val
    @version
end