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


65
66
67
# File 'app/api/endpoints/uuids.rb', line 65

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


48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/api/endpoints/uuids.rb', line 48

def self.attribute_delegate(*names)
  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


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

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

.create_bulk!(list_of_attributes) ⇒ Object

Raises:


75
76
77
78
79
80
81
82
# File 'app/api/endpoints/uuids.rb', line 75

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? { |a| a.is_a?(Hash) }

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

Instance Method Details

#findObject


84
85
86
# File 'app/api/endpoints/uuids.rb', line 84

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