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



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

def created_by val
  restrict :creator_id, val
end

#creator_of(val) ⇒ Object



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

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

#edited_by(val, action_table_id = nil, action_condition = nil) ⇒ Object

action_table_id and action_condition are needed to reuse that method for updated_by



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/card/query/relational_attributes.rb', line 44

def edited_by val, action_table_id=nil, action_condition=nil
  action_table_id ||= table_id true
  action_join = Join.new(
    from: self,
    to: ["card_actions", "an#{action_table_id}", "card_id"],
  )
  action_join.conditions << action_condition if action_condition
  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, action_table_id = nil, action_condition = nil) ⇒ Object

action_table_id and action_condition are needed to reuse that method for updater_of



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

def editor_of val, action_table_id=nil, action_condition=nil
  action_table_id ||= table_id true
  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#{action_table_id}", "card_act_id"],
    superjoin: act_join
  )
  # Join.new resets @conditions, so we have to set it after
  # initialization
  action_join.conditions << action_condition if action_condition
  join_cards val, from: action_join, from_field: "card_id"
end

#junction(val, side, to_field) ⇒ Object



110
111
112
113
114
# File 'lib/card/query/relational_attributes.rb', line 110

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



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

def last_edited_by val
  restrict :updater_id, val
end

#last_editor_of(val) ⇒ Object



72
73
74
# File 'lib/card/query/relational_attributes.rb', line 72

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

#left(val) ⇒ Object



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

def left val
  restrict :left_id, val
end

#left_plus(val) ⇒ Object

~~~~~~ PLUS RELATIONAL



98
99
100
# File 'lib/card/query/relational_attributes.rb', line 98

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

#member(val) ⇒ Object



92
93
94
# File 'lib/card/query/relational_attributes.rb', line 92

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

#member_of(val) ⇒ Object



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

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

#part(val) ⇒ Object



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

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

#plus(val) ⇒ Object



106
107
108
# File 'lib/card/query/relational_attributes.rb', line 106

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

#right(val) ⇒ Object



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

def right val
  restrict :right_id, val
end

#right_plus(val) ⇒ Object



102
103
104
# File 'lib/card/query/relational_attributes.rb', line 102

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

#type(val) ⇒ Object



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

def type val
  restrict :type_id, val
end

#updated_by(val) ⇒ Object

edited but not created



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

def updated_by val
  action_table_id = table_id true
  edited_by val, action_table_id, "an#{action_table_id}.action_type = 1"
end

#updater_of(val) ⇒ Object

editor but not creator



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

def updater_of val
  action_table_id = table_id true
  editor_of val, action_table_id, "an#{action_table_id}.action_type = 1"
end