Class: Vendor::Spec
- Inherits:
-
Object
- Object
- Vendor::Spec
- Defined in:
- lib/vendor/spec.rb
Constant Summary collapse
- ATTRIBUTES =
[ :name, :version, :email, :files, :homepage, :description, :authors, :source, :docs ]
- BUILD_SETTING_NAMES =
{ :other_linker_flags => "OTHER_LDFLAGS" }
Instance Attribute Summary collapse
-
#build_settings ⇒ Object
readonly
Returns the value of attribute build_settings.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#frameworks ⇒ Object
readonly
Returns the value of attribute frameworks.
Class Method Summary collapse
Instance Method Summary collapse
- #build_setting(setting, value) ⇒ Object
- #dependency(name, version = nil) ⇒ Object
- #framework(name) ⇒ Object
-
#initialize {|_self| ... } ⇒ Spec
constructor
A new instance of Spec.
- #to_json ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Spec
Returns a new instance of Spec.
43 44 45 46 |
# File 'lib/vendor/spec.rb', line 43 def initialize(&block) @attributes = {} yield(self) if block_given? end |
Instance Attribute Details
#build_settings ⇒ Object (readonly)
Returns the value of attribute build_settings.
10 11 12 |
# File 'lib/vendor/spec.rb', line 10 def build_settings @build_settings end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
8 9 10 |
# File 'lib/vendor/spec.rb', line 8 def dependencies @dependencies end |
#frameworks ⇒ Object (readonly)
Returns the value of attribute frameworks.
9 10 11 |
# File 'lib/vendor/spec.rb', line 9 def frameworks @frameworks end |
Class Method Details
.load(file) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vendor/spec.rb', line 32 def self.load(file) # Before evaling we need to chdir into the location of the vendorspec. This is # so if the vendorfile does any system calls, they're expecting to be in the right # right location. before = Dir.pwd Dir.chdir File.dirname(file) spec = eval File.read(file), nil, file Dir.chdir before spec end |
Instance Method Details
#build_setting(setting, value) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/vendor/spec.rb', line 48 def build_setting(setting, value) @build_settings ||= [] # If you pass in a symbol, it'll try and map it. if setting.kind_of?(Symbol) symbol = setting setting = BUILD_SETTING_NAMES[symbol] raise StandardError.new("No mapping for '#{symbol}' in #{BUILD_SETTING_NAMES.inspect}") unless setting end # YES/NO Mappings if value === true value = "YES" elsif value === false value = "NO" end @build_settings << [ setting, value ] end |
#dependency(name, version = nil) ⇒ Object
73 74 75 76 |
# File 'lib/vendor/spec.rb', line 73 def dependency(name, version = nil) @dependencies ||= [] @dependencies << [ name, version ] end |
#framework(name) ⇒ Object
68 69 70 71 |
# File 'lib/vendor/spec.rb', line 68 def framework(name) @frameworks ||= [] @frameworks << name end |
#to_json ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/vendor/spec.rb', line 88 def to_json [ ATTRIBUTES, :dependencies, :frameworks, :build_settings ].flatten.inject({}) do |hash, attr| val = self.send(attr) hash[attr] = val unless val.nil? hash end.to_json end |
#validate! ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/vendor/spec.rb', line 78 def validate! [ :name, :version, :email, :files ].each do |key| value = self.send(key) if value.respond_to?(:empty?) ? value.empty? : !value raise StandardError.new("Specification is missing the `#{key}` option") end end end |