class Troupe::Contract::PropertyTable

Public Class Methods

new() click to toggle source
# File lib/troupe/contract/property_table.rb, line 4
def initialize
  @table ||= {}
end

Public Instance Methods

all_properties() click to toggle source
# File lib/troupe/contract/property_table.rb, line 35
def all_properties
  expected_properties +
    permitted_properties +
    provided_properties
end
default_for(property_name) click to toggle source
# File lib/troupe/contract/property_table.rb, line 61
def default_for(property_name)
  @table[property_name].default
end
each_property() { |property_name, property| ... } click to toggle source
# File lib/troupe/contract/property_table.rb, line 17
def each_property
  @table.each do |property_name, property|
    yield property_name, property
  end
end
expected() click to toggle source
# File lib/troupe/contract/property_table.rb, line 31
def expected;  select(presence: :expected); end
expected_and_permitted_properties() click to toggle source
# File lib/troupe/contract/property_table.rb, line 45
def expected_and_permitted_properties
  expected_properties + permitted_properties
end
expected_properties() click to toggle source
# File lib/troupe/contract/property_table.rb, line 41
def expected_properties; expected.keys; end
get(property_name) click to toggle source
# File lib/troupe/contract/property_table.rb, line 8
def get(property_name)
  @table[property_name]
end
missing_properties(context) click to toggle source
# File lib/troupe/contract/property_table.rb, line 55
def missing_properties(context)
  expected_properties.select do |attr|
    !context.members.include?(attr)
  end
end
permitted() click to toggle source
# File lib/troupe/contract/property_table.rb, line 32
def permitted; select(presence: :permitted); end
permitted_properties() click to toggle source
# File lib/troupe/contract/property_table.rb, line 42
def permitted_properties; permitted.keys; end
provided() click to toggle source
# File lib/troupe/contract/property_table.rb, line 33
def provided;  select(presence: :provided); end
provided_properties() click to toggle source
# File lib/troupe/contract/property_table.rb, line 43
def provided_properties; provided.keys; end
select(args) click to toggle source
# File lib/troupe/contract/property_table.rb, line 23
def select(args)
  @table.select do |_, property|
    args == args.select do |k, v|
      property.send(k) == v
    end
  end
end
set(property_name, opts={}) click to toggle source
# File lib/troupe/contract/property_table.rb, line 12
def set(property_name, opts={})
  @table[property_name] ||= Property.new(opts)
  @table[property_name].merge!(opts)
end
undeclared_properties(context) click to toggle source
# File lib/troupe/contract/property_table.rb, line 49
def undeclared_properties(context)
  context.members.select do |attr|
    !expected_and_permitted_properties.include?(attr)
  end
end