Class: Husky::DataSource::MemoryRelation

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/husky/data_source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(set, caller, receiving_class) ⇒ MemoryRelation

Returns a new instance of MemoryRelation.



43
44
45
46
47
# File 'lib/husky/data_source.rb', line 43

def initialize(set, caller, receiving_class)
  @set             = set
  @caller          = caller
  @receiving_class = receiving_class
end

Instance Attribute Details

#callerObject (readonly)

Returns the value of attribute caller.



41
42
43
# File 'lib/husky/data_source.rb', line 41

def caller
  @caller
end

#receiving_classObject (readonly)

Returns the value of attribute receiving_class.



41
42
43
# File 'lib/husky/data_source.rb', line 41

def receiving_class
  @receiving_class
end

#setObject (readonly)

Returns the value of attribute set.



41
42
43
# File 'lib/husky/data_source.rb', line 41

def set
  @set
end

Instance Method Details

#caller_idObject



59
60
61
# File 'lib/husky/data_source.rb', line 59

def caller_id
  "#{caller.class.to_s.split('::').last.downcase}_id".to_sym
end

#eachObject



49
50
51
# File 'lib/husky/data_source.rb', line 49

def each
  set.map { |item| yield item }
end

#new(attributes) ⇒ Object



53
54
55
56
57
# File 'lib/husky/data_source.rb', line 53

def new(attributes)
  attrs = attributes
  attrs[caller_id] = caller.id
  receiving_class.new(attrs)
end