rasn1 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fc2ee81216604dd99cf1bd78ab08ddd732bf32f
4
- data.tar.gz: 66c4bece600e0a18f447f596c467ed76f5e4bbbc
3
+ metadata.gz: b4242a3051584aaa4b2f6d2603e45b1d516da098
4
+ data.tar.gz: fe8a39c6b026c8d408cc97417ab470b2cd8c8c88
5
5
  SHA512:
6
- metadata.gz: 93cc5dabca26821d3d9a44eab7099d9cd4f2011b250beb25ba97d44371db1eaa4b242b0b459a8bc4232fc0a5022bd762bcd1826edb6335688cae437738900601
7
- data.tar.gz: dc6a6cb74e5b0bdb84c3fb3f6faff06a979d7221b0f8caa025a06a193c672ca7c1e2732d1a106f1b7f99ca8b60f7790089832fa5fa8ff845283ccb26ffc750f5
6
+ metadata.gz: 3ef413c1ce1070a8d0d647e66a8022ae38947a71cb8d2b2ce1947379162459fe94fe6d1e53f2b4656d336e48efc66db22b33027010273b22b517ee2994048009
7
+ data.tar.gz: 2998c9805c9e0f017b5e1cb994ddb26de41e393f670da34429de4104eaa319cb7fdeeefd60badd75c08aacb3b43be6f0cd9c915e3d2a59670987066be3986100
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1
4
+ - 2.2.7
5
+ - 2.3.4
6
+ - 2.4.1
7
+ install:
8
+ - bundler install --path vendor/bundle --jobs=3 --retry=3
9
+ script:
10
+ - bundler exec rake
data/lib/rasn1/model.rb CHANGED
@@ -68,6 +68,32 @@ module RASN1
68
68
  @root = [name, model_klass]
69
69
  end
70
70
 
71
+ # Update options of root element.
72
+ # May be used when subclassing.
73
+ # class Model1 < RASN1::Model
74
+ # sequence :seq, implicit: 0,
75
+ # content: [bool(:bool), integer(:int)]
76
+ # end
77
+ #
78
+ # # same as Model1 but with implicit tag set to 1
79
+ # class Model2 < Model1
80
+ # root_options implicit: 1
81
+ # end
82
+ # @param [Hash] options
83
+ # @return [void]
84
+ def root_options(options)
85
+ @options = options
86
+ end
87
+
88
+ # On inheritance, create +@root+ class variable
89
+ # @param [Class] klass
90
+ # @return [void]
91
+ def inherited(klass)
92
+ super
93
+ root = @root
94
+ klass.class_eval { @root = root }
95
+ end
96
+
71
97
  # @method sequence(name, options)
72
98
  # @see Types::Sequence#initialize
73
99
  # @method set(name, options)
@@ -76,8 +102,8 @@ module RASN1
76
102
  # @see Types::Choice#initialize
77
103
  %w(sequence set choice).each do |type|
78
104
  class_eval "def #{type}(name, options={})\n" \
79
- " proc = Proc.new do\n" \
80
- " Types::#{type.capitalize}.new(name, options)\n" \
105
+ " proc = Proc.new do |opts|\n" \
106
+ " Types::#{type.capitalize}.new(name, options.merge(opts))\n" \
81
107
  " end\n" \
82
108
  " @root = [name, proc]\n" \
83
109
  " @root << options[:content] unless options[:content].nil?\n" \
@@ -92,8 +118,8 @@ module RASN1
92
118
  %w(sequence set).each do |type|
93
119
  klass_name = "Types::#{type.capitalize}Of"
94
120
  class_eval "def #{type}_of(name, type, options={})\n" \
95
- " proc = Proc.new do\n" \
96
- " #{klass_name}.new(name, type, options)\n" \
121
+ " proc = Proc.new do |opts|\n" \
122
+ " #{klass_name}.new(name, type, options.merge(opts))\n" \
97
123
  " end\n" \
98
124
  " @root = [name, proc]\n" \
99
125
  "end"
@@ -116,7 +142,9 @@ module RASN1
116
142
  Types.primitives.each do |prim|
117
143
  next if prim == Types::ObjectId
118
144
  class_eval "def #{prim.type.downcase.gsub(/\s+/, '_')}(name, options={})\n" \
119
- " proc = Proc.new { #{prim.to_s}.new(name, options) }\n" \
145
+ " proc = Proc.new do |opts|\n" \
146
+ " #{prim.to_s}.new(name, options.merge(opts))\n" \
147
+ " end\n" \
120
148
  " @root = [name, proc]\n" \
121
149
  "end"
122
150
  end
@@ -125,13 +153,13 @@ module RASN1
125
153
  # +Object#object_id+.
126
154
  # @see Types::ObjectId#initialize
127
155
  def objectid(name, options={})
128
- proc = Proc.new { Types::ObjectId.new(name, options) }
156
+ proc = Proc.new { |opts| Types::ObjectId.new(name, options.merge(opts)) }
129
157
  @root = [name, proc]
130
158
  end
131
159
 
132
160
  # @see Types::Any#initialize
133
161
  def any(name, options={})
134
- proc = Proc.new { Types::Any.new(name, options) }
162
+ proc = Proc.new { |opts| Types::Any.new(name, options.merge(opts)) }
135
163
  @root = [name, proc]
136
164
  end
137
165
 
@@ -240,10 +268,10 @@ module RASN1
240
268
  [Types::SequenceOf, Types::SetOf].include? el.class
241
269
  end
242
270
 
243
- def get_type(proc_or_class, name=nil)
271
+ def get_type(proc_or_class, options={})
244
272
  case proc_or_class
245
273
  when Proc
246
- proc_or_class.call
274
+ proc_or_class.call(options)
247
275
  when Class
248
276
  proc_or_class.new
249
277
  end
@@ -253,14 +281,14 @@ module RASN1
253
281
  root = self.class.class_eval { @root }
254
282
  @root = root[0]
255
283
  @elements = {}
256
- @elements[@root] = get_type(root[1])
284
+ @elements[@root] = get_type(root[1], self.class.class_eval { @options } || {})
257
285
  root
258
286
  end
259
287
 
260
288
  def set_elements(name, el, content=nil)
261
289
  if content.is_a? Array
262
290
  @elements[name].value = content.map do |name2, proc_or_class, content2|
263
- subel = get_type(proc_or_class, name2)
291
+ subel = get_type(proc_or_class)
264
292
  @elements[name2] = subel
265
293
  if is_composed?(subel) and content2.is_a? Array
266
294
  set_elements(name2, proc_or_class, content2)
data/lib/rasn1/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RASN1
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rasn1
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Daubert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-10 00:00:00.000000000 Z
11
+ date: 2017-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -88,6 +88,7 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
+ - ".travis.yml"
91
92
  - Gemfile
92
93
  - LICENSE
93
94
  - README.md