Class: Vendor::Spec
- Inherits:
-
Object
- Object
- Vendor::Spec
- Defined in:
- lib/vendor/spec.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Hash
readonly
A hash that contains the attributes defined for the specification.
-
#authors ⇒ Object
The authors responsible for this project.
- #build_settings ⇒ Object readonly
- #dependencies ⇒ Object readonly
-
#description ⇒ Object
A description to give users context about this particular vendor specification.
-
#docs ⇒ Object
The location where a user could find the documentation about the vendor specification.
-
#email ⇒ Object
The email that a user could use to contact with support issues.
-
#files ⇒ Object
The source files to include in this release of the vendor specification.
- #frameworks ⇒ Object readonly
-
#homepage ⇒ Object
The homepage where a user could find more information about the project.
-
#name ⇒ Object
The name of the vendor specification.
-
#per_file_flag ⇒ Object
Specifying a build target specific flag for the source files.
-
#resources ⇒ Object
The resource files to include in this release of the vendor specification.
-
#source ⇒ Object
The location where a user could find the original source code.
-
#version ⇒ Object
The version of this release.
Class Method Summary collapse
-
.attribute(name, options = {}) ⇒ Object
Define various attributes of a vendor specification.
-
.load(file) ⇒ Vendor::Spec
Load the specified Vendor specification file.
- .on_validate(&block) ⇒ Object
-
.validate(spec_instance) ⇒ Object
Perform a validation on an instance of a Vendor::Spec.
Instance Method Summary collapse
-
#build_setting(setting, value) ⇒ void
Add additional build configuration information required for the specification to build and run succesfully on the installed system.
-
#dependency(name, version = nil) ⇒ void
Specify any additional dependencies for the vendor specification.
-
#framework(name) ⇒ void
Load any additional system frameworks or system libraries required by the project.
-
#initialize(&block) {|_self| ... } ⇒ Spec
constructor
Create a new specification.
-
#to_json ⇒ Object
A JSON representation of the vendor specification which will be packaged and shipped with the other files.
-
#validate! ⇒ void
Validate the instance.
Constructor Details
#initialize(&block) {|_self| ... } ⇒ Spec
Create a new specification
Vendor::Spec.new do |s|
s.name "DKBenchmark"
s.version "0.1"
s. "keithpitt"
s.email "[email protected]"
s.description "Easy benchmarking in Objective-C using blocks"
s.files [ "DKBenchmark.h", "DKBenchmark.m" ]
end
48 49 50 51 52 53 54 |
# File 'lib/vendor/spec.rb', line 48 def initialize(&block) @attributes = {} @build_settings = [] @frameworks = [] @dependencies = [] yield(self) if block_given? end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
Returns a hash that contains the attributes defined for the specification. These attributes should be set through the dynamic methods defined for each attribute.
59 60 61 |
# File 'lib/vendor/spec.rb', line 59 def attributes @attributes end |
#authors ⇒ Object
The authors responsible for this project
168 |
# File 'lib/vendor/spec.rb', line 168 attribute :authors |
#build_settings ⇒ Object (readonly)
188 189 190 |
# File 'lib/vendor/spec.rb', line 188 def build_settings @build_settings end |
#dependencies ⇒ Object (readonly)
259 260 261 |
# File 'lib/vendor/spec.rb', line 259 def dependencies @dependencies end |
#description ⇒ Object
A description to give users context about this particular vendor specification
164 |
# File 'lib/vendor/spec.rb', line 164 attribute :description |
#docs ⇒ Object
The location where a user could find the documentation about the vendor specification.
185 |
# File 'lib/vendor/spec.rb', line 185 attribute :docs |
#email ⇒ Object
The email that a user could use to contact with support issues
172 |
# File 'lib/vendor/spec.rb', line 172 attribute :email, :required |
#files ⇒ Object
The source files to include in this release of the vendor specification
152 |
# File 'lib/vendor/spec.rb', line 152 attribute :files, :required |
#frameworks ⇒ Object (readonly)
224 225 226 |
# File 'lib/vendor/spec.rb', line 224 def frameworks @frameworks end |
#homepage ⇒ Object
The homepage where a user could find more information about the project
176 |
# File 'lib/vendor/spec.rb', line 176 attribute :homepage |
#name ⇒ Object
The name of the vendor specification
144 |
# File 'lib/vendor/spec.rb', line 144 attribute :name, :required |
#per_file_flag ⇒ Object
Specifying a build target specific flag for the source files
160 |
# File 'lib/vendor/spec.rb', line 160 attribute :per_file_flag |
#resources ⇒ Object
The resource files to include in this release of the vendor specification
156 |
# File 'lib/vendor/spec.rb', line 156 attribute :resources |
#source ⇒ Object
The location where a user could find the original source code
180 |
# File 'lib/vendor/spec.rb', line 180 attribute :source |
#version ⇒ Object
The version of this release
148 |
# File 'lib/vendor/spec.rb', line 148 attribute :version, :required |
Class Method Details
.attribute(name, options = {}) ⇒ Object
Define various attributes of a vendor specification. This method is to be used internally within the class as a DSL to define various methods and validations.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/vendor/spec.rb', line 102 def self.attribute(name, = {}) = { => nil } unless .is_a? Hash # Define a traditional setter for the attribute define_method "#{name}=" do |value| @attributes[name] = value end # Define a getter or a setter (depending if the method has been called with # arguments or not) define_method "#{name}" do |*args| if args.length == 1 @attributes[name] = args.first else @attributes[name] end end # Define validations for the properties which are marked as required if .key?(:required) on_validate do |instance| value = instance.send(name) if value.respond_to?(:empty?) ? value.empty? : !value raise StandardError.new("Specification is missing the `#{name}` option") end end end end |
.load(file) ⇒ Vendor::Spec
the following method performs an ‘eval` with the source found within the specificed file. This could contain any action native to ruby which may lead to unintended or malicous effects.
Load the specified Vendor specification file. A vendor specification file is simply the Ruby code to generate a specificatio
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/spec.rb', line 17 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 |
.on_validate(&block) ⇒ Object
66 67 68 |
# File 'lib/vendor/spec.rb', line 66 def self.on_validate(&block) (@validations ||= []) << block end |
.validate(spec_instance) ⇒ Object
Perform a validation on an instance of a Vendor::Spec. This is intended to be called from the instance itself through the #validate! method.
76 77 78 79 80 |
# File 'lib/vendor/spec.rb', line 76 def self.validate(spec_instance) @validations.each do |validation| validation.call(spec_instance) end end |
Instance Method Details
#build_setting(setting, value) ⇒ void
currently all build settings that are added here will be uniquely appended to the existing build settings of the target configuration that
The settings can be specified as their environment variable string (e.g. “GCC_PRECOMPILE_PREFIX_HEADER”). Some of the common properties can be referenced by symbolic names (e.g. :precompile_prefix_headers). The current list of supported symbolic names is available in the Xcoder gem.
This method returns an undefined value.
Add additional build configuration information required for the specification to build and run succesfully on the installed system.
218 219 220 |
# File 'lib/vendor/spec.rb', line 218 def build_setting(setting, value) @build_settings << [ setting, value ] end |
#dependency(name, version = nil) ⇒ void
This method returns an undefined value.
Specify any additional dependencies for the vendor specification.
269 270 271 |
# File 'lib/vendor/spec.rb', line 269 def dependency(name, version = nil) @dependencies << [ name, version ] end |
#framework(name) ⇒ void
Frameworks can be specifiedy with or without the framework file extension. Also it is assumed that all frameworks specified are system frameworks and can be found alongside the other system frameworks.
Dynamic system libraries must be specified with the ‘dylib` file extension. It is assumed that the all system libraries can be found in the `/user/lib` folder.
This method returns an undefined value.
Load any additional system frameworks or system libraries required by the project.
254 255 256 |
# File 'lib/vendor/spec.rb', line 254 def framework(name) @frameworks << name end |
#to_json ⇒ Object
Returns a JSON representation of the vendor specification which will be packaged and shipped with the other files.
277 278 279 280 281 282 283 |
# File 'lib/vendor/spec.rb', line 277 def to_json [ @attributes.keys, :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! ⇒ void
This method returns an undefined value.
Validate the instance. If the vendor specification is considered invalid an exception will be raised that describes the nature of the validation.
87 88 89 |
# File 'lib/vendor/spec.rb', line 87 def validate! self.class.validate(self) end |