Class: Vendor::Spec

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/spec.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) {|_self| ... } ⇒ Spec

Create a new specification

Vendor::Spec.new do |s|

  s.name           "DKBenchmark"
  s.version        "0.1"

  s.authors        "keithpitt"
  s.email          "[email protected]"
  s.description    "Easy benchmarking in Objective-C using blocks"
  s.files          [ "DKBenchmark.h", "DKBenchmark.m" ]

end

Parameters:

  • block (Block)

    the specified block given allows for additional configuration of the Specificattion.

Yields:

  • (_self)

Yield Parameters:

  • _self (Vendor::Spec)

    the object that the method was called on



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

#attributesHash (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.

Returns:

  • (Hash)

    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

#authorsObject

The authors responsible for this project



168
# File 'lib/vendor/spec.rb', line 168

attribute :authors

#build_settingsObject (readonly)

See Also:



188
189
190
# File 'lib/vendor/spec.rb', line 188

def build_settings
  @build_settings
end

#dependenciesObject (readonly)

See Also:



259
260
261
# File 'lib/vendor/spec.rb', line 259

def dependencies
  @dependencies
end

#descriptionObject

A description to give users context about this particular vendor specification



164
# File 'lib/vendor/spec.rb', line 164

attribute :description

#docsObject

The location where a user could find the documentation about the vendor specification.



185
# File 'lib/vendor/spec.rb', line 185

attribute :docs

#emailObject

The email that a user could use to contact with support issues



172
# File 'lib/vendor/spec.rb', line 172

attribute :email, :required

#filesObject

The source files to include in this release of the vendor specification



152
# File 'lib/vendor/spec.rb', line 152

attribute :files, :required

#frameworksObject (readonly)

See Also:



224
225
226
# File 'lib/vendor/spec.rb', line 224

def frameworks
  @frameworks
end

#homepageObject

The homepage where a user could find more information about the project



176
# File 'lib/vendor/spec.rb', line 176

attribute :homepage

#nameObject

The name of the vendor specification



144
# File 'lib/vendor/spec.rb', line 144

attribute :name, :required

#per_file_flagObject

Specifying a build target specific flag for the source files



160
# File 'lib/vendor/spec.rb', line 160

attribute :per_file_flag

#resourcesObject

The resource files to include in this release of the vendor specification



156
# File 'lib/vendor/spec.rb', line 156

attribute :resources

#sourceObject

The location where a user could find the original source code



180
# File 'lib/vendor/spec.rb', line 180

attribute :source

#versionObject

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.

Parameters:

  • name (String, Symbol)

    the name of the attribute that will have various getters, setters, and validators generated.

  • options (Hash, Symbol) (defaults to: {})

    additional parameters that allow additional configuration of the properties



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,options = {})

  options = { options => nil } unless options.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 options.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

Note:

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

Returns:

  • (Vendor::Spec)

    the Vendor::Spec parse and evaluated fom the specified file.



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

Parameters:

  • block (Block)

    define a validation for the specified attribute to ensure that it meets the criteria required for it to be saved properly to the vendor specification



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.

See Also:



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

Note:

currently all build settings that are added here will be uniquely appended to the existing build settings of the target configuration that

Note:

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.

Examples:

Specifying build configuration


Vendor::Spec.new do |spec|
  spec.build_setting 'GCC_PRECOMPILE_PREFIX_HEADER', 'YES'
  spec.build_settings :user_header_search_paths, '/custom/header/search/path'
end

Parameters:

  • setting (String, Symbol)

    the target configuration setting name

  • value (String, Symbol, Array)

    will be appended to the existing values for the given configuration.

See Also:



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.

Parameters:

  • name (String)

    is the name of the required library

  • version (String) (defaults to: nil)

    the required version by this specification



269
270
271
# File 'lib/vendor/spec.rb', line 269

def dependency(name, version = nil)
  @dependencies << [ name, version ]
end

#framework(name) ⇒ void

Note:

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.

Note:

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.

Examples:

Specifying framework with or without the framework extension


Vendor::Spec.new do |spec|
  spec.framework 'CoreGraphics.framework'
  spec.framework 'UIKit'
end

Specifying dynamic library


Vendor::Spec.new do |spec|
  spec.framework 'libz.dylib'
end

Parameters:

  • name (String)

    of the System framework



254
255
256
# File 'lib/vendor/spec.rb', line 254

def framework(name)
  @frameworks << name
end

#to_jsonObject

Returns a JSON representation of the vendor specification which will be packaged and shipped with the other files.

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