Sha256: d1e1cb24f78dce7eb31d71ccb19384fce9bd619fe7c2ea28ad4d006811d5483a

Contents?: true

Size: 1.28 KB

Versions: 12

Compression:

Stored size: 1.28 KB

Contents

class Card
  module Query
    class CardQuery
      # interpret CQL attributes that involve references from one card to another
      module ReferenceAttributes
        def self.define_reference_method methodname, reftype, ref_method, ref_field
          define_method methodname do |val|
            tie :reference,
                { ref_method => { reftype: reftype, card: val } },
                { to: ref_field }
          end
        end

        {
          refer_to: %w[L I],
          link_to: "L",
          include: "I",
          nest: "I"
        }.each do |methodname, reftype|
          define_reference_method methodname, reftype, :referee, :referer_id
        end

        {
          referred_to_by: %w[L I],
          linked_to_by: "L",
          included_by: "I",
          nested_by: "I"
        }.each do |methodname, reftype|
          define_reference_method methodname, reftype, :referer, :referee_id
        end

        # shortcut methods for role references
        # DEPRECATE?

        def member_of val
          interpret referred_to_by: { left: val, right: { codename: "members" } }
        end

        def member val
          interpret type_id: Card::RoleID,
                    right_plus: [{ codename: "members" }, refer_to: val]
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
card-1.108.1 lib/card/query/card_query/reference_attributes.rb
card-1.108.0 lib/card/query/card_query/reference_attributes.rb
card-1.107.0 lib/card/query/card_query/reference_attributes.rb
card-1.106.0 lib/card/query/card_query/reference_attributes.rb
card-1.105.6 lib/card/query/card_query/reference_attributes.rb
card-1.105.5 lib/card/query/card_query/reference_attributes.rb
card-1.105.4 lib/card/query/card_query/reference_attributes.rb
card-1.105.3 lib/card/query/card_query/reference_attributes.rb
card-1.105.2.pre1 lib/card/query/card_query/reference_attributes.rb
card-1.105.2 lib/card/query/card_query/reference_attributes.rb
card-1.105.1 lib/card/query/card_query/reference_attributes.rb
card-1.105.0 lib/card/query/card_query/reference_attributes.rb