Module: Card::Query::RelationalAttributes

Included in:
Card::Query
Defined in:
lib/card/query/relational_attributes.rb

Instance Method Summary collapse

Instance Method Details

#created_by(val) ⇒ Object



62
63
64
# File 'lib/card/query/relational_attributes.rb', line 62

def created_by val
  restrict :creator_id, val
end

#creator_of(val) ⇒ Object



58
59
60
# File 'lib/card/query/relational_attributes.rb', line 58

def creator_of val
  join_cards val, to_field: "creator_id"
end

#edited_by(val) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/card/query/relational_attributes.rb', line 36

def edited_by val
  action_join = Join.new(
    from: self,
    to: ["card_actions", "an#{table_id true}", "card_id"]
  )
  joins << action_join
  act_join = Join.new(
    from: action_join,
    from_field: "card_act_id",
    to: ["card_acts", "a#{table_id true}"]
  )
  join_cards val, from: act_join, from_field: "actor_id"
end

#editor_of(val) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/card/query/relational_attributes.rb', line 22

def editor_of val
  act_join = Join.new(
    from: self,
    to: ["card_acts", "a#{table_id true}", "actor_id"]
  )
  joins << act_join
  action_join = Join.new(
    from: act_join,
    to: ["card_actions", "an#{table_id true}", "card_act_id"],
    superjoin: act_join
  )
  join_cards val, from: action_join, from_field: "card_id"
end

#junction(val, side, to_field) ⇒ Object



88
89
90
91
92
# File 'lib/card/query/relational_attributes.rb', line 88

def junction val, side, to_field
  part_clause, junction_clause = val.is_a?(Array) ? val : [val, {}]
  junction_val = clause_to_hash(junction_clause).merge side => part_clause
  join_cards junction_val, to_field: to_field
end

#last_edited_by(val) ⇒ Object



54
55
56
# File 'lib/card/query/relational_attributes.rb', line 54

def last_edited_by val
  restrict :updater_id, val
end

#last_editor_of(val) ⇒ Object



50
51
52
# File 'lib/card/query/relational_attributes.rb', line 50

def last_editor_of val
  join_cards val, to_field: "updater_id"
end

#left(val) ⇒ Object



14
15
16
# File 'lib/card/query/relational_attributes.rb', line 14

def left val
  restrict :left_id, val
end

#left_plus(val) ⇒ Object

~~~~~~ PLUS RELATIONAL



76
77
78
# File 'lib/card/query/relational_attributes.rb', line 76

def left_plus val
  junction val, :left, :right_id
end

#member(val) ⇒ Object



70
71
72
# File 'lib/card/query/relational_attributes.rb', line 70

def member val
  interpret referred_to_by: { left: val, right: RolesID }
end

#member_of(val) ⇒ Object



66
67
68
# File 'lib/card/query/relational_attributes.rb', line 66

def member_of val
  interpret right_plus: [RolesID, refer_to: val]
end

#part(val) ⇒ Object



9
10
11
12
# File 'lib/card/query/relational_attributes.rb', line 9

def part val
  right_val = val.is_a?(Integer) ? val : val.clone
  any(left: val, right: right_val)
end

#plus(val) ⇒ Object



84
85
86
# File 'lib/card/query/relational_attributes.rb', line 84

def plus val
  any(left_plus: val, right_plus: val.deep_clone)
end

#right(val) ⇒ Object



18
19
20
# File 'lib/card/query/relational_attributes.rb', line 18

def right val
  restrict :right_id, val
end

#right_plus(val) ⇒ Object



80
81
82
# File 'lib/card/query/relational_attributes.rb', line 80

def right_plus val
  junction val, :right, :left_id
end

#type(val) ⇒ Object



5
6
7
# File 'lib/card/query/relational_attributes.rb', line 5

def type val
  restrict :type_id, val
end