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
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
462 463 464 465 466 467 468 469 470 471 472 473 |
# File 'lib/spiderfw/app.rb', line 462 def self.array_attribute(name, ={}) @@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
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, ={}) @@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 [: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
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
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
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
509 510 511 512 513 |
# File 'lib/spiderfw/app.rb', line 509 def (val = nil) = [val] if val ||= [] [0] end |
#eval(text, path = nil) ⇒ AppSpec
Evals the given code in the AppSpec’s context
533 534 535 536 |
# File 'lib/spiderfw/app.rb', line 533 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
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_list ⇒ Array
Returns an Array of optional gem names
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_dependencies ⇒ Array
Returns an array of apps needed at runtime
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
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
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_h ⇒ Hash
Returns all attributes as an 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
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
502 503 504 505 |
# File 'lib/spiderfw/app.rb', line 502 def version(val=nil) @version = Gem::Version.new(val) if val @version end |