ALD 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/ALD.rb +6 -5
- data/lib/ALD/definition.rb +114 -2
- data/lib/ALD/exceptions.rb +17 -0
- data/lib/ALD/package.rb +28 -13
- data/lib/ALD/package_generator.rb +4 -4
- metadata +78 -16
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 445063876e8fc4783ef501709c428536506a6dd2
|
4
|
+
data.tar.gz: dada4d739c9e78df7e9d5137ba84fe041fe97303
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bda2ebf48adbcf07d5a9e8b7daea6f82d46d5d4e9d26bf2863b2e9fd73c41c0be14e4836b22b655ad3aebef1cb461129f31f8f67e380fbca9eb173a17a1aed30
|
7
|
+
data.tar.gz: e4d7807db45aba618920471ae6406193e268ebfdd905bd2bb4f51b237c6538589e8740231c4efec5818690fc250c81ed26797b76203077a1e8fb842250dbd22f
|
data/lib/ALD.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
require_relative 'ALD/package'
|
2
|
+
require_relative 'ALD/package_generator'
|
3
|
+
require_relative 'ALD/definition'
|
4
|
+
require_relative 'ALD/definition_generator.rb'
|
5
|
+
require_relative 'ALD/exceptions'
|
6
|
+
require_relative 'ALD/api'
|
6
7
|
|
7
8
|
module ALD
|
8
9
|
end
|
data/lib/ALD/definition.rb
CHANGED
@@ -1,16 +1,25 @@
|
|
1
1
|
require 'nokogiri'
|
2
|
-
|
2
|
+
require_relative 'exceptions'
|
3
3
|
|
4
4
|
module ALD
|
5
|
+
# Public: Access information in ALD package definition files.
|
5
6
|
class Definition
|
7
|
+
# Internal: Path to the file containing the XML Schema Definition used for
|
8
|
+
# definition validation.
|
6
9
|
SCHEMA_FILE = "#{File.dirname(__FILE__)}/schema.xsd"
|
7
10
|
|
11
|
+
# Internal: The XML namespace used by the definitions.
|
8
12
|
XML_NAMESPACE = 'ald://package/schema/2014'
|
9
13
|
|
14
|
+
# Internal: The XML Schema instance used for validation
|
15
|
+
#
|
16
|
+
# Returns the Nokogiri::XML::Schema instance representing ::SCHEMA_FILE.
|
10
17
|
def self.schema
|
11
18
|
@schema ||= Nokogiri::XML::Schema(File.read(SCHEMA_FILE))
|
12
19
|
end
|
13
20
|
|
21
|
+
# Internal: The array of attributes which are defined in the root element
|
22
|
+
# of a definition. Each of these gets a dynamically defined method.
|
14
23
|
TOPLEVEL_ATTRIBUTES = %w[
|
15
24
|
id
|
16
25
|
name
|
@@ -19,12 +28,74 @@ module ALD
|
|
19
28
|
summary
|
20
29
|
]
|
21
30
|
|
31
|
+
# Public: Gets the ID of the item to be represented by this definition.
|
32
|
+
#
|
33
|
+
# Examples
|
34
|
+
#
|
35
|
+
# puts "Item ID: #{definition.id}"
|
36
|
+
#
|
37
|
+
# Signature
|
38
|
+
#
|
39
|
+
# id()
|
40
|
+
|
41
|
+
# Public: Gets the name of the item defined by this definition.
|
42
|
+
#
|
43
|
+
# Examples
|
44
|
+
#
|
45
|
+
# puts "The item is called '#{definition.name}'"
|
46
|
+
#
|
47
|
+
# Signature
|
48
|
+
#
|
49
|
+
# name()
|
50
|
+
|
51
|
+
# Public: Gets the semver version of this definition's item.
|
52
|
+
#
|
53
|
+
# Examples
|
54
|
+
#
|
55
|
+
# puts "#{definition.name} v#{definition.version}"
|
56
|
+
#
|
57
|
+
# Signature
|
58
|
+
#
|
59
|
+
# version()
|
60
|
+
|
61
|
+
# Public: Gets the type of item this definition represents.
|
62
|
+
#
|
63
|
+
# Examples
|
64
|
+
#
|
65
|
+
# puts "Item type is #{definition.type}"
|
66
|
+
#
|
67
|
+
# Signature
|
68
|
+
#
|
69
|
+
# type()
|
70
|
+
|
71
|
+
# Public: Gets the item's summary text.
|
72
|
+
#
|
73
|
+
# Examples
|
74
|
+
#
|
75
|
+
# puts "\n#{definition.summary}\n"
|
76
|
+
#
|
77
|
+
# Signature
|
78
|
+
#
|
79
|
+
# summary()
|
80
|
+
|
22
81
|
TOPLEVEL_ATTRIBUTES.each do |attr|
|
23
82
|
define_method attr.to_sym do
|
24
83
|
@document.xpath("//@ald:#{attr}", 'ald' => XML_NAMESPACE)[0].value
|
25
84
|
end
|
26
85
|
end
|
27
86
|
|
87
|
+
# Public: Open a new definition file for analysis.
|
88
|
+
#
|
89
|
+
# source - the source to read the definition from. This can be a
|
90
|
+
# Nokogiri::XML::Document, a String or any object that responds to
|
91
|
+
# #read and #close.
|
92
|
+
#
|
93
|
+
# Examples
|
94
|
+
#
|
95
|
+
# definition = ALD::Definition.new('/path/to/def.xml')
|
96
|
+
#
|
97
|
+
# Raises ALD::InvalidDefinitionError if the supplied source is not a valid
|
98
|
+
# ALD package definition.
|
28
99
|
def initialize(source)
|
29
100
|
if source.is_a? Nokogiri::XML::Document
|
30
101
|
@document = source
|
@@ -35,35 +106,76 @@ module ALD
|
|
35
106
|
raise InvalidDefinitionError unless valid?
|
36
107
|
end
|
37
108
|
|
109
|
+
# Public: Get the defined item's description.
|
110
|
+
#
|
111
|
+
# Returns the description String.
|
38
112
|
def description
|
39
113
|
@document.xpath("//ald:description", 'ald' => XML_NAMESPACE)[0].text
|
40
114
|
end
|
41
115
|
|
116
|
+
# Public: Get the defined item's tags.
|
117
|
+
#
|
118
|
+
# Examples
|
119
|
+
#
|
120
|
+
# definition.tags.each { |tag| puts " - #{tag}" }
|
121
|
+
#
|
122
|
+
# Returns the Array of Strings that the item is tagged with.
|
42
123
|
def tags
|
43
124
|
@document.xpath("//ald:tags/ald:tag/@ald:name", 'ald' => XML_NAMESPACE).map { |tag| tag.value }
|
44
125
|
end
|
45
126
|
|
127
|
+
# Public: Get the item's authors information
|
128
|
+
#
|
129
|
+
# Examples
|
130
|
+
#
|
131
|
+
# definition.authors.each do |author|
|
132
|
+
# puts "Author: #{author['name']}"
|
133
|
+
# puts "\tUser name: #{author['user-name'] || '(unknown)'}"
|
134
|
+
# puts "\tHomepage: #{author['homepage'] || '(unknown)'}"
|
135
|
+
# puts "\tEmail: #{author['email'] || '(unknown)'}"
|
136
|
+
# end
|
137
|
+
#
|
138
|
+
# Returns an Array of Hashes, where each Hash has the 'name' key and *may*
|
139
|
+
# also have 'user-name', 'homepage' and 'email' keys.
|
46
140
|
def authors
|
47
141
|
attribute_hash '//ald:authors/ald:author', %w[name user-name homepage email]
|
48
142
|
end
|
49
143
|
|
144
|
+
# Public: Gets additional links this definition references
|
145
|
+
#
|
146
|
+
# Returns an Array of Hashes, where each Hash has the keys 'name', 'href'
|
147
|
+
# and 'description'-
|
50
148
|
def links
|
51
149
|
attribute_hash '//ald:links/ald:link', %w[name description href]
|
52
150
|
end
|
53
151
|
|
152
|
+
# Internal: Check if the definition is valid.
|
153
|
+
# Library consumers need not call this, as ::new already does.
|
154
|
+
#
|
155
|
+
# Returns true, if the definition is valid according to the schema, false
|
156
|
+
# otherwise.
|
54
157
|
def valid?
|
55
158
|
Definition.schema.valid?(@document)
|
56
159
|
end
|
57
160
|
|
161
|
+
# Public: Get the XML string representing the definition
|
58
162
|
def to_s
|
59
163
|
@document.to_s
|
60
164
|
end
|
61
165
|
|
62
166
|
private
|
63
167
|
|
168
|
+
# Internal: Get an Array of attribute Hashes from a list of elements in the
|
169
|
+
# definition.
|
170
|
+
#
|
171
|
+
# xpath - the XPath String pointing to the XML elements in the definition
|
172
|
+
# keys - the Array of keys to retrieve from the elements
|
173
|
+
#
|
174
|
+
# Returns an Array of Hashes, where each Hash has all those of the given
|
175
|
+
# keys that were actual attributes on the relevant element.
|
64
176
|
def attribute_hash(xpath, keys)
|
65
177
|
@document.xpath(xpath, 'ald' => XML_NAMESPACE).map do |e|
|
66
|
-
Hash[keys.map { |k| e.attribute_with_ns(k, XML_NAMESPACE) }.
|
178
|
+
Hash[keys.map { |k| e.attribute_with_ns(k, XML_NAMESPACE) }.compact.map { |a| [a.node_name, a.value] }]
|
67
179
|
end
|
68
180
|
end
|
69
181
|
end
|
data/lib/ALD/exceptions.rb
CHANGED
@@ -7,4 +7,21 @@ module ALD
|
|
7
7
|
|
8
8
|
class InvalidDefinitionError < StandardError
|
9
9
|
end
|
10
|
+
|
11
|
+
class API
|
12
|
+
class RequestError < StandardError
|
13
|
+
end
|
14
|
+
|
15
|
+
class AuthenticationError < RequestError
|
16
|
+
end
|
17
|
+
|
18
|
+
class UnsupportedAuthMethodError < AuthenticationError
|
19
|
+
end
|
20
|
+
|
21
|
+
class NoAuthError < AuthenticationError
|
22
|
+
end
|
23
|
+
|
24
|
+
class InvalidAuthError < AuthenticationError
|
25
|
+
end
|
26
|
+
end
|
10
27
|
end
|
data/lib/ALD/package.rb
CHANGED
@@ -1,22 +1,29 @@
|
|
1
1
|
require 'zip'
|
2
|
-
|
3
|
-
|
2
|
+
require_relative 'definition'
|
3
|
+
require_relative 'exceptions'
|
4
4
|
|
5
5
|
module ALD
|
6
|
-
# Represents an ALD package file containing an app or library and its
|
6
|
+
# Public: Represents an ALD package file containing an app or library and its
|
7
|
+
# definition.
|
7
8
|
class Package
|
8
9
|
|
9
|
-
# The rubyzip Zip::File object containing the data
|
10
|
+
# Internal: The rubyzip Zip::File object containing the data.
|
10
11
|
attr_reader :archive
|
11
12
|
|
12
|
-
# The ALD::Definition instance representing the definition contained
|
13
|
+
# Public: The ALD::Definition instance representing the definition contained
|
14
|
+
# in the package. Use this to extract all the information on the package.
|
13
15
|
attr_reader :definition
|
14
16
|
|
15
|
-
# Opens a new ALD package file
|
17
|
+
# Public: Opens a new ALD package file.
|
16
18
|
#
|
17
|
-
# file - a
|
19
|
+
# file - a String representing the path to the file or a Zip::File instance
|
18
20
|
#
|
19
21
|
# Returns a new ALD::Package instance representing the package file
|
22
|
+
#
|
23
|
+
# Raises ALD::NoDefinitionError if the package contains no definition file.
|
24
|
+
#
|
25
|
+
# Raises ALD::InvalidPackageError if the package is not valid according to
|
26
|
+
# its definition.
|
20
27
|
def initialize(file)
|
21
28
|
if file.is_a? Zip::File
|
22
29
|
@archive = file
|
@@ -30,27 +37,35 @@ module ALD
|
|
30
37
|
@definition = Definition.new(def_entry.get_input_stream)
|
31
38
|
raise InvalidPackageError, 'The given ZIP file is not a valid ALD archive!' unless Package.valid?(@archive, @definition)
|
32
39
|
|
33
|
-
# file access
|
40
|
+
# todo: file access
|
34
41
|
end
|
35
42
|
|
36
|
-
# Closes a no longer required package
|
43
|
+
# Public: Closes a no longer required package. While this method has little
|
44
|
+
# effect for now, calling it should be considered best practice and ensures
|
45
|
+
# forward-compatibility.
|
46
|
+
#
|
47
|
+
# Returns nothing.
|
37
48
|
def close
|
38
49
|
@archive.close
|
39
50
|
end
|
40
51
|
|
41
|
-
# Alias for new
|
52
|
+
# Public: Alias for ::new
|
42
53
|
def self.open(file)
|
43
54
|
new(file)
|
44
55
|
end
|
45
56
|
|
46
|
-
# Tests if a given archive is a valid ALD package
|
57
|
+
# Public: Tests if a given archive is a valid ALD package. Although part of
|
58
|
+
# the public API, most library consumers will not need to call it, as it is
|
59
|
+
# already called by ::new.
|
60
|
+
#
|
61
|
+
# Not yet implemented.
|
47
62
|
#
|
48
|
-
# file
|
63
|
+
# file - a Zip::File instance for the package
|
49
64
|
# definition - an ALD::Definition instance the package must meet
|
50
65
|
#
|
51
66
|
# Returns true if it is valid, false otherwise
|
52
67
|
def self.valid?(file, definition)
|
53
|
-
true
|
68
|
+
true # todo
|
54
69
|
end
|
55
70
|
end
|
56
71
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require_relative 'definition'
|
2
|
+
require_relative 'definition_generator'
|
3
|
+
require_relative 'package'
|
4
|
+
require_relative 'exceptions'
|
5
5
|
|
6
6
|
module ALD
|
7
7
|
class Package
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ALD
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- maul.esel
|
@@ -14,7 +13,6 @@ dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rubyzip
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: nokogiri
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,27 +34,94 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: net-http-digest_auth
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: semantic
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
46
69
|
- !ruby/object:Gem::Dependency
|
47
70
|
name: rake
|
48
71
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
72
|
requirements:
|
51
|
-
- -
|
73
|
+
- - '>='
|
52
74
|
- !ruby/object:Gem::Version
|
53
75
|
version: '0'
|
54
76
|
type: :development
|
55
77
|
prerelease: false
|
56
78
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
79
|
requirements:
|
59
|
-
- -
|
80
|
+
- - '>='
|
60
81
|
- !ruby/object:Gem::Version
|
61
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rdoc
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.17'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.17'
|
62
125
|
description: A gem containing helpers for the ALD API, the ALD package format and
|
63
126
|
ALD package definitions.
|
64
127
|
email:
|
@@ -76,26 +139,25 @@ files:
|
|
76
139
|
homepage: https://github.com/Library-Distribution/ALD.rb
|
77
140
|
licenses:
|
78
141
|
- MIT
|
142
|
+
metadata: {}
|
79
143
|
post_install_message:
|
80
144
|
rdoc_options: []
|
81
145
|
require_paths:
|
82
146
|
- lib
|
83
147
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
148
|
requirements:
|
86
|
-
- -
|
149
|
+
- - '>='
|
87
150
|
- !ruby/object:Gem::Version
|
88
151
|
version: '0'
|
89
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
153
|
requirements:
|
92
|
-
- -
|
154
|
+
- - '>='
|
93
155
|
- !ruby/object:Gem::Version
|
94
156
|
version: '0'
|
95
157
|
requirements: []
|
96
158
|
rubyforge_project:
|
97
|
-
rubygems_version:
|
159
|
+
rubygems_version: 2.0.3
|
98
160
|
signing_key:
|
99
|
-
specification_version:
|
161
|
+
specification_version: 4
|
100
162
|
summary: Utility gem for the ALD protocol
|
101
163
|
test_files: []
|