Module: NetSuite::Support::Fields::ClassMethods
- Defined in:
- lib/netsuite/support/fields.rb
Instance Method Summary collapse
- #field(name, klass = nil) ⇒ Object
- #fields(*args) ⇒ Object
- #read_only_field(name) ⇒ Object
- #read_only_fields(*args) ⇒ Object
- #search_only_field(name) ⇒ Object
- #search_only_fields(*args) ⇒ Object
Instance Method Details
#field(name, klass = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/netsuite/support/fields.rb', line 22 def field(name, klass = nil) name_sym = name.to_sym raise "#{name} already defined on #{self.name}" if fields.include?(name_sym) raise "#{name} conflicts with a method defined on #{self.name}" if method_defined?(name_sym) fields << name_sym if klass define_method(name_sym) do attributes[name_sym] ||= klass.new end define_method("#{name_sym}=") do |value| if value.nil? attributes.delete(name_sym) else attributes[name_sym] = value.kind_of?(klass) ? value : klass.new(value) end end else define_method(name_sym) do attributes[name_sym] end define_method("#{name_sym}=") do |value| attributes[name_sym] = value end end end |
#fields(*args) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/netsuite/support/fields.rb', line 12 def fields(*args) if args.empty? @fields ||= Set.new else args.each do |arg| field arg end end end |
#read_only_field(name) ⇒ Object
61 62 63 64 65 |
# File 'lib/netsuite/support/fields.rb', line 61 def read_only_field(name) name_sym = name.to_sym read_only_fields << name_sym field name end |
#read_only_fields(*args) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/netsuite/support/fields.rb', line 51 def read_only_fields(*args) if args.empty? @read_only_fields ||= Set.new else args.each do |arg| read_only_field arg end end end |
#search_only_field(name) ⇒ Object
77 78 79 80 81 |
# File 'lib/netsuite/support/fields.rb', line 77 def search_only_field(name) name_sym = name.to_sym search_only_fields << name_sym field name end |
#search_only_fields(*args) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/netsuite/support/fields.rb', line 67 def search_only_fields(*args) if args.empty? @search_only_fields ||= Set.new else args.each do |arg| search_only_field arg end end end |