Module: Svnx::Base::Fields
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#assign(args, symbols = Array.new) ⇒ Object
shortcut for “@var = args”, for multiple variable names, which are symbols.
- #create_invalid_fields_message(fields) ⇒ Object
- #fields ⇒ Object
-
#validate(args, valid = Array.new) ⇒ Object
raises an exception if any element in
args
is not invalid
.
Methods included from ClassMethods
attr_readers, has_field, has_fields
Class Method Details
.included(other) ⇒ Object
67 68 69 |
# File 'lib/svnx/base/fields.rb', line 67 def self.included other other.extend ClassMethods end |
Instance Method Details
#assign(args, symbols = Array.new) ⇒ Object
shortcut for “@var = args”, for multiple variable names, which are symbols.
12 13 14 15 16 |
# 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) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/svnx/base/fields.rb', line 24 def 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 ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# 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) ⇒ Object
raises an exception if any element in args
is not in valid
.
19 20 21 22 |
# 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( invalid) end |