module Svnx::Base::Fields

Public Class Methods

included(other) click to toggle source
# File lib/svnx/base/fields.rb, line 67
def self.included other
  other.extend ClassMethods
end

Public Instance Methods

assign(args, symbols = Array.new) click to toggle source

shortcut for “@var = args”, for multiple variable names, which are symbols.

# File lib/svnx/base/fields.rb, line 12
def assign args, symbols = Array.new
  symbols.each do |symbol|
    instance_variable_set "@" + symbol.to_s, args[symbol]
  end
end
create_invalid_fields_message(fields) click to toggle source
# File lib/svnx/base/fields.rb, line 24
def create_invalid_fields_message fields
  Array.new.tap do |a|
    a << "invalid"
    a << (fields.size == 1 ? "field" : "fields" )
    a << "for"
    a << self.class.to_s + ":"
    a.concat fields
  end.join(" ")
end
fields() click to toggle source
# File lib/svnx/base/fields.rb, line 34
def fields
  # instance variable on the class itself, not an instance of the class
  varname = '@fields'
  cls = self.class
  if cls.instance_variable_defined? varname
    cls.instance_variable_get varname
  else
    false
  end
end
validate(args, valid = Array.new) click to toggle source

raises an exception if any element in args is not in valid.

# File lib/svnx/base/fields.rb, line 19
def validate args, valid = Array.new
  invalid = args.keys.reject { |field| valid.include? field }
  invalid.empty? || raise(create_invalid_fields_message invalid)
end