Class: SimpleAMS::Options::Relations

Inherits:
Array
  • Object
show all
Defined in:
lib/simple_ams/options/relations.rb

Defined Under Namespace

Classes: Relation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relations, includes = nil) ⇒ Relations

Returns a new instance of Relations.



7
8
9
10
11
12
# File 'lib/simple_ams/options/relations.rb', line 7

def initialize(relations, includes = nil)
  @relations = relations
  @includes = includes

  super(relations.map { |rel| Relations::Relation.new(*rel) })
end

Instance Attribute Details

#includesObject (readonly)

Returns the value of attribute includes.



5
6
7
# File 'lib/simple_ams/options/relations.rb', line 5

def includes
  @includes
end

#relationsObject (readonly)

Returns the value of attribute relations.



5
6
7
# File 'lib/simple_ams/options/relations.rb', line 5

def relations
  @relations
end

Instance Method Details

#availableObject



14
15
16
17
18
19
20
21
# File 'lib/simple_ams/options/relations.rb', line 14

def available
  return @available ||= self if includes.nil?
  return @available ||= [] if includes.empty?

  @available ||= self.select  do |relation|
    includes.include?(relation.name)
  end
end