diff --git a/.rubocop.yml b/.rubocop.yml index bbc3b8e4..a9c9c064 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -41,7 +41,7 @@ Naming/FileName: Metrics/AbcSize: CountRepeatedAttributes: false - Max: 25 + Max: 30 Metrics/ClassLength: Max: 150 diff --git a/_packages/ruby/lib/apple_data/data_file.rb b/_packages/ruby/lib/apple_data/data_file.rb index a6cf5d1c..6b05cb5b 100644 --- a/_packages/ruby/lib/apple_data/data_file.rb +++ b/_packages/ruby/lib/apple_data/data_file.rb @@ -159,7 +159,7 @@ def construct_hash(collection_definition, value) [key, instance] end - result.to_h + result.to_h.with_indifferent_access end end end diff --git a/_packages/ruby/lib/apple_data/dsl/data_file_definition.rb b/_packages/ruby/lib/apple_data/dsl/data_file_definition.rb index 6842736b..bff7ca2f 100644 --- a/_packages/ruby/lib/apple_data/dsl/data_file_definition.rb +++ b/_packages/ruby/lib/apple_data/dsl/data_file_definition.rb @@ -9,13 +9,21 @@ def initialize @methods = {} end - def collection(name, mapper = nil, &) - @collections[name] = AppleData::DSL::CollectionDefinition.new(name, mapper) - if block_given? && @collections[name].mapper.nil? - @collections[name].mapper = Class.new(AppleData::SchemaBase) - @collections[name].mapper.class_eval(&) + def collection(collection_name, mapper = nil, &) + data_collection_name = self.class.name + @collections[collection_name] = AppleData::DSL::CollectionDefinition.new(collection_name, mapper) + if block_given? && @collections[collection_name].mapper.nil? + @collections[collection_name].mapper = Class.new(AppleData::SchemaBase) + @collections[collection_name].mapper.const_set(:DATA_COLLECTION_NAME, data_collection_name) + @collections[collection_name].mapper.const_set(:COLLECTION_NAME, collection_name) + @collections[collection_name].mapper.instance_eval do + def name + "#{self.class.const_get(:DATA_COLLECTION_NAME)}:#{self.class.const_get(:COLLECTION_NAME)}" + end + end + @collections[collection_name].mapper.class_eval(&) end - @collections[name] + @collections[collection_name] end def define_method(name, &proc) diff --git a/_packages/ruby/lib/apple_data/schemas/pki.rb b/_packages/ruby/lib/apple_data/schemas/pki.rb index a2047ece..68b73c8f 100644 --- a/_packages/ruby/lib/apple_data/schemas/pki.rb +++ b/_packages/ruby/lib/apple_data/schemas/pki.rb @@ -15,6 +15,9 @@ end collection :oids do + attr_accessor :key + + attribute :name, :string attribute :title, :string attribute :type, :string attribute :description, :string @@ -22,5 +25,9 @@ attribute :found_in, :string, collection: true attribute :issuers, :string, collection: true attribute :ous, :string, collection: true + + define_method :to_s do + [name, title, description, key].reject(&:blank?).first + end end end diff --git a/spec/apple_data/schemas/pki_spec.rb b/spec/apple_data/schemas/pki_spec.rb new file mode 100644 index 00000000..6aa00142 --- /dev/null +++ b/spec/apple_data/schemas/pki_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +RSpec.describe AppleData::Schemas::PKI do + let(:instance) { described_class.new } + + it 'has entries' do + aggregate_failures do + expect(instance.oids).to be_a(Hash) + expect(instance.oids).not_to be_empty + end + end + + it 'has entries that respond to #to_s' do + aggregate_failures do + expect(instance.oids[:'1.2.840.113635.100.6.1.15'].to_s).to be_a(String) + expect(instance.oids[:'1.2.840.113635.100.6.1.15'].to_s).to eq 'appleImg4Manifest' + end + end +end