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

#branch(val = nil) ⇒ Object

The git branch used for the app



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

def branch
  @branch
end

Class Method Details

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

Helper method to define an Array attribute on the AppSpec class

Returns:

  • (nil)


462
463
464
465
466
467
468
469
470
471
472
473
# File 'lib/spiderfw/app.rb', line 462

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

Returns:

  • (nil)


442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/spiderfw/app.rb', line 442

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

Parameters:

  • text (String)

    code to evaluate

  • path (String) (defaults to: nil)

    path to the code

Returns:



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

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

Parameters:

Returns:



526
527
528
# File 'lib/spiderfw/app.rb', line 526

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

Parameters:

  • h (Hash)

Returns:



567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
# File 'lib/spiderfw/app.rb', line 567

def self.parse_hash(h)
    spec = self.new
    h.each do |key, value|
        unless spec.respond_to?(:"#{key}")
            Spider.output("Bad spec key #{key} in:", :ERROR)
            Spider.output(h.inspect, :ERROR)
            next
        end
        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

Returns:



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

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

Returns:



533
534
535
536
# File 'lib/spiderfw/app.rb', line 533

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

Returns:

  • (Array)


593
594
595
# File 'lib/spiderfw/app.rb', line 593

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

Returns:

  • (Array)


599
600
601
# File 'lib/spiderfw/app.rb', line 599

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

Returns:

  • (Array)


586
587
588
589
# File 'lib/spiderfw/app.rb', line 586

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

Returns:



495
496
497
# File 'lib/spiderfw/app.rb', line 495

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

#load(spec_path) ⇒ self

Loads attributes from a .spec file

Parameters:

Returns:

  • (self)


518
519
520
521
# File 'lib/spiderfw/app.rb', line 518

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

#to_hHash

Returns all attributes as an Hash

Returns:

  • (Hash)


548
549
550
551
552
553
554
555
# File 'lib/spiderfw/app.rb', line 548

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

Parameters:

  • opts (Hash) (defaults to: nil)

    JSON options

Returns:



560
561
562
# File 'lib/spiderfw/app.rb', line 560

def to_json(opts=nil)
    to_h.to_json
end

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

Sets or retrieves the AppSpec version

Parameters:

  • val (String) (defaults to: nil)

Returns:

  • (Gem::Version)


502
503
504
505
# File 'lib/spiderfw/app.rb', line 502

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