cfplist 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "rbconfig"
5
+
6
+ # Force clang compilation
7
+ RbConfig::CONFIG["SDKROOT"] = %x(xcrun --sdk macosx --show-sdk-path)
8
+ RbConfig::MAKEFILE_CONFIG["CC"] = "clang"
9
+ RbConfig::MAKEFILE_CONFIG["CXX"] = "clang++"
10
+
11
+ def ensure_framework(framework)
12
+ have_framework(framework) || raise("#{framework} framework not found!")
13
+ have_header("#{framework}/#{framework}.h") || raise("Could not find #{framework}.h!")
14
+ end
15
+
16
+ def ensure_frameworks(*frameworks)
17
+ frameworks.each do |framework|
18
+ ensure_framework(framework)
19
+ end
20
+ end
21
+
22
+ ensure_framework "CoreFoundation"
23
+
24
+ dir_config "cfplist"
25
+
26
+ create_makefile("cfplist/cfplist")
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cfplist/version"
4
+ require "cfplist/cfplist"
5
+
6
+ # Main CFPlist Module.
7
+ module CFPlist
8
+ class << self
9
+ def [](object, opts = {})
10
+ if object.respond_to? :to_str
11
+ CFPlist.parse(object.to_str, opts)
12
+ else
13
+ CFPlist.generate(object, opts)
14
+ end
15
+ end
16
+ end
17
+
18
+ module_function
19
+
20
+ def parse(data, opts = {})
21
+ symbolize_keys = opts.fetch(:symbolize_keys, false)
22
+ _parse(data, symbolize_keys)
23
+ end
24
+
25
+ def generate(obj, opts = {})
26
+ _generate(obj, opts)
27
+ end
28
+
29
+ class << self
30
+ # Default options for {#load}.
31
+ # Initially:
32
+ # opts = CFPlist.load_default_options
33
+ # opts # => {:symbolize_keys => false}
34
+ # @return [Hash{Symbol => Boolean}]
35
+ attr_accessor :load_default_options
36
+ end
37
+ self.load_default_options = {
38
+ symbolize_keys: false
39
+ }
40
+
41
+ def load(source, proc = nil, options = {})
42
+ opts = load_default_options.merge(options)
43
+ if source.respond_to?(:to_str)
44
+ source = source.to_str
45
+ elsif source.respond_to?(:to_io)
46
+ source = source.to_io.read
47
+ elsif source.respond_to?(:read)
48
+ source = source.read
49
+ end
50
+
51
+ result = parse(source, opts)
52
+ recurse_proc(result, &proc) if proc
53
+ result
54
+ end
55
+
56
+ # Recursively calls passed _Proc_ if the parsed data structure is an _Array_
57
+ # or a _Hash_.
58
+ def recurse_proc(result, &proc) # :nodoc:
59
+ case result
60
+ when Array
61
+ result.each { |x| recurse_proc(x, &proc) }
62
+ proc.call(result)
63
+ when Hash
64
+ result.each { |_k, _v| recurse_proc(x, &proc); recurse_proc(y, &proc) }
65
+ proc.call(result)
66
+ else
67
+ proc.call(result)
68
+ end
69
+ end
70
+
71
+ alias restore load
72
+ module_function :restore
73
+
74
+ class << self
75
+ # Default options for {#parse}
76
+ # Initially:
77
+ # opts = CFPlist.dump_default_options
78
+ # opts # => {}
79
+ # @return [Hash{Symbol => Boolean}]
80
+ attr_accessor :dump_default_options
81
+ end
82
+ self.dump_default_options = {}
83
+
84
+ def dump(object, an_io = nil, limit = nil)
85
+ if an_io && limit.nil?
86
+ an_io = an_io.to_io if an_io.respond_to?(:to_io)
87
+ unless an_io.respond_to?(:write)
88
+ limit = an_io
89
+ an_io = nil
90
+ end
91
+ end
92
+
93
+ opts = CFPlist.dump_default_options
94
+ opts = opts.merge(max_nesting: limit) if limit
95
+ result = generate(object, opts)
96
+
97
+ if an_io
98
+ an_io.write(result)
99
+ an_io
100
+ else
101
+ result
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CFPlist
4
+ VERSION = "0.1.1"
5
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cfplist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - J. Morgan Lieberthal
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-12-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Native bindings for CoreFoundation PropertyList files. Note that this
14
+ gem requires the CoreFoundation framework be present on the system, so it will only
15
+ work on macOS.
16
+ email:
17
+ - j.morgan.lieberthal@gmail.com
18
+ executables: []
19
+ extensions:
20
+ - ext/cfplist/extconf.rb
21
+ extra_rdoc_files: []
22
+ files:
23
+ - ".clang-format"
24
+ - ".gitignore"
25
+ - ".rspec"
26
+ - ".rubocop.yml"
27
+ - ".ruby-version"
28
+ - ".simplecov"
29
+ - ".travis.yml"
30
+ - CHANGELOG
31
+ - CODE_OF_CONDUCT.md
32
+ - Gemfile
33
+ - Gemfile.lock
34
+ - LICENSE.txt
35
+ - README.md
36
+ - Rakefile
37
+ - bin/console
38
+ - bin/setup
39
+ - cfplist.gemspec
40
+ - compile_commands.json
41
+ - ext/cfplist/cfplist.c
42
+ - ext/cfplist/extconf.rb
43
+ - lib/cfplist.rb
44
+ - lib/cfplist/version.rb
45
+ homepage: https://github.com/baberthal/cfplist
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ homepage_uri: https://github.com/baberthal/cfplist
50
+ source_code_uri: https://github.com/baberthal/cfplist
51
+ changelog_uri: https://github.com/baberthal/cfplist/blob/prime/CHANGELOG
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.6.0
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.1.4
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: CoreFoundation PropertyList Native Bindings
71
+ test_files: []