Class: Spider::App::AppSpec
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
-
#branch(val = nil) ⇒ Object
The git branch used for the app.
Class Method Summary collapse
-
.array_attribute(name, options = {}) ⇒ nil
Helper method to define an Array attribute on the AppSpec class.
-
.attribute(name, options = {}) ⇒ nil
Helper method to define an attribute on the AppSpec class.
-
.eval(text, path = nil) ⇒ AppSpec
Returns a new AppSpec instance, evaluating the given code.
-
.load(spec_path) ⇒ AppSpec
Returns a new AppSpec instance, loading from a .spec file.
-
.parse_hash(h) ⇒ AppSpec
Constructs a new AppSpec instance from an Hash of attributes.
Instance Method Summary collapse
-
#author(val = nil) ⇒ String
Sets or retrieves the first AppSpec author.
-
#eval(text, path = nil) ⇒ AppSpec
Evals the given code in the AppSpec’s context.
-
#gems_list ⇒ Array
Returns an Array of gem names for gems this AppSpec depends on.
-
#gems_optional_list ⇒ Array
Returns an Array of optional gem names.
-
#get_runtime_dependencies ⇒ Array
Returns an array of apps needed at runtime.
-
#id(val = nil) ⇒ String
Sets or retrieves the AppSpec id.
-
#load(spec_path) ⇒ self
Loads attributes from a .spec file.
-
#to_h ⇒ Hash
Returns all attributes as an Hash.
-
#to_json(opts = nil) ⇒ String
Returns the Hash (as in #to_hash) as JSON.
-
#version(val = nil) ⇒ Gem::Version
Sets or retrieves the AppSpec version.
Instance Attribute Details
#branch(val = nil) ⇒ Object
The git branch used for the app
495 496 497 |
# File 'lib/spiderfw/app.rb', line 495 def branch @branch end |
Class Method Details
.array_attribute(name, options = {}) ⇒ nil
Helper method to define an Array attribute on the AppSpec class
466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'lib/spiderfw/app.rb', line 466 def self.array_attribute(name, ={}) @@attributes << name str = <<END_OF_EVAL def #{name}(*vals) @#{name} = vals unless vals.empty? @#{name} ||= [] @#{name} end END_OF_EVAL class_eval(str) nil end |
.attribute(name, options = {}) ⇒ nil
Helper method to define an attribute on the AppSpec class
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/spiderfw/app.rb', line 446 def self.attribute(name, ={}) @@attributes << name str = <<END_OF_EVAL def #{name}(val=nil) @#{name} = val if val @#{name} ||= #{[:default].inspect} @#{name} end alias :#{name}= :#{name} END_OF_EVAL if [:default].is_a?(TrueClass) || [: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
546 547 548 |
# File 'lib/spiderfw/app.rb', line 546 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
530 531 532 |
# File 'lib/spiderfw/app.rb', line 530 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
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 |
# File 'lib/spiderfw/app.rb', line 571 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
513 514 515 516 517 |
# File 'lib/spiderfw/app.rb', line 513 def (val = nil) @authors = [val] if val @authors ||= [] @authors[0] end |
#eval(text, path = nil) ⇒ AppSpec
Evals the given code in the AppSpec’s context
537 538 539 540 |
# File 'lib/spiderfw/app.rb', line 537 def eval(text, path=nil) self.instance_eval(text) self end |
#gems_list ⇒ Array
Returns an Array of gem names for gems this AppSpec depends on
597 598 599 |
# File 'lib/spiderfw/app.rb', line 597 def gems_list self.gems.map{ |g| g.is_a?(Array) ? g.first : g } end |
#gems_optional_list ⇒ Array
Returns an Array of optional gem names
603 604 605 |
# File 'lib/spiderfw/app.rb', line 603 def gems_optional_list self.gems_optional.map{ |g| g.is_a?(Array) ? g.first : g } end |
#get_runtime_dependencies ⇒ Array
Returns an array of apps needed at runtime
590 591 592 593 |
# File 'lib/spiderfw/app.rb', line 590 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
499 500 501 |
# File 'lib/spiderfw/app.rb', line 499 def id(val=nil) self.app_id(val) end |
#load(spec_path) ⇒ self
Loads attributes from a .spec file
522 523 524 525 |
# File 'lib/spiderfw/app.rb', line 522 def load(spec_path) self.eval(File.read(spec_path), spec_path) self end |
#to_h ⇒ Hash
Returns all attributes as an Hash
552 553 554 555 556 557 558 559 |
# File 'lib/spiderfw/app.rb', line 552 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
564 565 566 |
# File 'lib/spiderfw/app.rb', line 564 def to_json(opts=nil) to_h.to_json end |
#version(val = nil) ⇒ Gem::Version
Sets or retrieves the AppSpec version
506 507 508 509 |
# File 'lib/spiderfw/app.rb', line 506 def version(val=nil) @version = Gem::Version.new(val) if val @version end |