Class: Endpoints::Uuids::Search

Inherits:
Object
  • Object
show all
Includes:
Validateable
Defined in:
app/api/endpoints/uuids.rb

Defined Under Namespace

Classes: CriteriaInvalid

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Validateable

append_features, #method_missing, #validate!

Constructor Details

#initialize(attributes) ⇒ Search

Returns a new instance of Search.



70
71
72
# File 'app/api/endpoints/uuids.rb', line 70

def initialize(attributes)
  @lookup = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Validateable

Class Method Details

.attribute_delegate(*names) ⇒ Object

rubocop:todo Metrics/MethodLength



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/api/endpoints/uuids.rb', line 49

def self.attribute_delegate(*names) # rubocop:todo Metrics/MethodLength
  names.each do |name|
    line = __LINE__ + 1
    class_eval(
      "
      def #{name}
        return nil unless lookup.respond_to?(:fetch)
        lookup[#{name.to_s.inspect}]
      end
      protected #{name.to_sym.inspect}
    ",
      __FILE__,
      line
    )
  end
end

.create!(attributes) ⇒ Object



74
75
76
77
78
# File 'app/api/endpoints/uuids.rb', line 74

def self.create!(attributes)
  search = new(attributes)
  search.validate! {}
  search
end

.create_bulk!(list_of_attributes) ⇒ Object

Raises:



80
81
82
83
84
85
86
87
# File 'app/api/endpoints/uuids.rb', line 80

def self.create_bulk!(list_of_attributes)
  raise CriteriaInvalid, 'should be an array of tuples' if list_of_attributes.nil?
  raise CriteriaInvalid, 'should be an array of tuples' unless list_of_attributes.is_a?(Array)
  raise CriteriaInvalid, "can't be blank" if list_of_attributes.blank?
  raise CriteriaInvalid, 'should be a tuple' unless list_of_attributes.all?(Hash)

  list_of_attributes.map(&method(:create!))
end

Instance Method Details

#findObject



89
90
91
# File 'app/api/endpoints/uuids.rb', line 89

def find
  Uuid.find_uuid_instance!(model.classify, id)
end