Class: Datory::Attributes::Collection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/datory/attributes/collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(collection = Set.new) ⇒ Collection

Returns a new instance of Collection.



9
10
11
# File 'lib/datory/attributes/collection.rb', line 9

def initialize(collection = Set.new)
  @collection = collection
end

Instance Method Details

#find_by(name:) ⇒ Object



13
14
15
# File 'lib/datory/attributes/collection.rb', line 13

def find_by(name:)
  find { |attribute| attribute.from.name == name }
end

#include_class_exist?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/datory/attributes/collection.rb', line 21

def include_class_exist?
  @include_class_exist ||= filter do |attribute| # rubocop:disable Performance/Count
    include_class = attribute.to.include_class

    next false if include_class.nil?

    if [Set, Array].include?(include_class)
      include_class.any? { |item| item <= Datory::Base }
    else
      include_class <= Datory::Base
    end
  end.size.positive?
end

#internal_namesObject



17
18
19
# File 'lib/datory/attributes/collection.rb', line 17

def internal_names
  map { |attribute| attribute.to.name }
end