gir_ffi 0.14.0 → 0.14.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
  SHA256:
3
- metadata.gz: 2fc709e79ed9d8d423b39d2793e648a3d4cf62603496f5398fe80515a756fe96
4
- data.tar.gz: 2ca46650022b545f0dff670fc8bbaa27c159ed43c101fde1d674ab064b4dec36
3
+ metadata.gz: c32084045b640a22901bdd0d256ce8b8df1ace345930d3e4fccfd0e598b82b19
4
+ data.tar.gz: 5ac1e06a4dd28b4589ca93e30c48218a4cffb40f18d9f8c87859fdd76460fc8c
5
5
  SHA512:
6
- metadata.gz: ad913da79bffc07e693e94aa2e56aa0b425c48999b84ffcee0a92a06439b75a46cd7db04f19cb5bc87b8869c541b7b374538c9aea300c2ffbf973d50f8b8bc5c
7
- data.tar.gz: d661d30631b2470b85f9ff59abf36e2c63f380ba94f40a5b98eb0e5fd1ebb0943b94c5b6dff2cb6737bc264746c014f5c24e080fceea13b7eb20a2de8077f54e
6
+ metadata.gz: f70592c52c01f747ca9370007783231007ef535a0039337aaf42e46a17acbf2a54178b33c591ca8658e040496bb66a34ffd1f8126b2b323470783b97418418ae
7
+ data.tar.gz: fd92518d3541a1c46ebfe4758af76e8f746cf7ae355797a7f5736cdb4bc4b8444f6e9b4be7bf08712155759b11e5d697c2bdb522f3a4241337446204e5fb13c3
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.14.1 / 2018-09-27
4
+
5
+ * Add enum values as constants in the generated module.
6
+
3
7
  ## 0.14.0 / 2018-09-25
4
8
 
5
9
  * Do not generate field accessors for Object types. Object data should normally
@@ -26,6 +26,7 @@ module GirFFI
26
26
  setup_ffi_type
27
27
  klass.extend superclass
28
28
  setup_constants
29
+ setup_value_constants
29
30
  stub_methods
30
31
  setup_inspect
31
32
  end
@@ -40,6 +41,14 @@ module GirFFI
40
41
  end
41
42
  end
42
43
 
44
+ def setup_value_constants
45
+ info.values.each do |vinfo|
46
+ optionally_define_constant klass, vinfo.constant_name do
47
+ vinfo.value
48
+ end
49
+ end
50
+ end
51
+
43
52
  def setup_inspect
44
53
  klass.instance_eval <<-RUBY, __FILE__, __LINE__ + 1
45
54
  def self.inspect
@@ -11,6 +11,7 @@ require 'gir_ffi/info_ext/i_registered_type_info'
11
11
  require 'gir_ffi/info_ext/i_signal_info'
12
12
  require 'gir_ffi/info_ext/i_type_info'
13
13
  require 'gir_ffi/info_ext/i_unresolved_info'
14
+ require 'gir_ffi/info_ext/i_value_info'
14
15
  require 'gir_ffi/info_ext/i_vfunc_info'
15
16
  require 'gir_ffi/info_ext/safe_constant_name'
16
17
  require 'gir_ffi/info_ext/safe_function_name'
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GirFFI
4
+ module InfoExt
5
+ # Extensions for GObjectIntrospection::IValueInfo needed by GirFFI
6
+ module IValueInfo
7
+ def constant_name
8
+ upcased_name = name.upcase
9
+ if upcased_name =~ /^[0-9]/
10
+ "VALUE_#{upcased_name}"
11
+ else
12
+ upcased_name
13
+ end
14
+ end
15
+
16
+ def to_callback_ffi_type
17
+ return :pointer if direction != :in
18
+
19
+ argument_type.to_callback_ffi_type
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ GObjectIntrospection::IValueInfo.send :include, GirFFI::InfoExt::IValueInfo
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Current GirFFI version
4
4
  module GirFFI
5
- VERSION = '0.14.0'.freeze
5
+ VERSION = '0.14.1'.freeze
6
6
  end
@@ -3,20 +3,21 @@
3
3
  require 'gir_ffi_test_helper'
4
4
 
5
5
  describe GirFFI::Builders::EnumBuilder do
6
- describe 'creating Regress::TestEnum' do
7
- before do
8
- save_module :Regress
9
- end
6
+ describe '#build_class' do
7
+ let(:info) { get_introspection_data 'Regress', 'TestEnum' }
8
+ let(:builder) { GirFFI::Builders::EnumBuilder.new info }
10
9
 
11
10
  it 'makes the created type know its proper name' do
12
- info = get_introspection_data 'Regress', 'TestEnum'
13
- builder = GirFFI::Builders::EnumBuilder.new info
14
11
  enum = builder.build_class
15
12
  enum.inspect.must_equal 'Regress::TestEnum'
16
13
  end
17
14
 
18
- after do
19
- restore_module :Regress
15
+ it 'adds constants for the values' do
16
+ enum = builder.build_class
17
+ enum::VALUE1.must_equal enum[:value1]
18
+ enum::VALUE2.must_equal enum[:value2]
19
+ enum::VALUE3.must_equal enum[:value3]
20
+ enum::VALUE4.must_equal enum[:value4]
20
21
  end
21
22
  end
22
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gir_ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matijs van Zuijlen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-25 00:00:00.000000000 Z
11
+ date: 2018-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -284,6 +284,7 @@ files:
284
284
  - lib/gir_ffi/info_ext/i_signal_info.rb
285
285
  - lib/gir_ffi/info_ext/i_type_info.rb
286
286
  - lib/gir_ffi/info_ext/i_unresolved_info.rb
287
+ - lib/gir_ffi/info_ext/i_value_info.rb
287
288
  - lib/gir_ffi/info_ext/i_vfunc_info.rb
288
289
  - lib/gir_ffi/info_ext/safe_constant_name.rb
289
290
  - lib/gir_ffi/info_ext/safe_function_name.rb