module Seatbelt::Property::ClassMethods
Public Instance Methods
Public: All properties that are marked as accessible.
Returns the property list or an empty Array.
# File lib/seatbelt/core/property.rb, line 56 def accessible_properties @accessible_properties ||= [] end
Public: Mass defining of properties.
See define_property
for details
-
properties - A list of property names to define.
# File lib/seatbelt/core/property.rb, line 49 def define_properties(*properties) properties.each { |property| define_property(property) } end
Public: Defines an API property. This is only working if its called within the interface method block.
Wraps Seatbelt::Pool::Api#api_method
with a getter and setter method name.
*args - An argument list containing:
name - Name of the API property (required) options - An optional options Hash containing: :accessible - Property is mass assignable (defaults to false)
Examples:
class Book interface :instance do define_property :author define_property :title end end
# File lib/seatbelt/core/property.rb, line 24 def define_property(*args) if @scope.eql?(:class) raise Seatbelt::Errors::PropertyOnClassLevelDefinedError end hsh = {} options = args.extract_options! accessible = options.fetch(:accessible, false) name = args.pop hsh[:scope] = @scope self.send(:api_method, name, hsh) hsh[:args] = [:value] self.send(:api_method, :"#{name}=", hsh) property_list << name self.send(:property_accessible, name) if accessible end
Public: Defines one or more properties to be mass assignable due the properties= setter method.
If the class implements an attributes method (e.g. coming from Seatbelt::Document
) these attributes are includeable in this list too.
properties - A list of property names. Requires at least one property.
# File lib/seatbelt/core/property.rb, line 68 def property_accessible(*properties) properties.each do |property| attribute_defined = false if self.respond_to?(:attributes) if self.attribute_set.map(&:name).include?(property) attribute_defined = true end end unless attribute_defined unless property_list.include?(property) && !attribute_defined raise Seatbelt::Errors::PropertyNotDefinedYetError.new(property) end end accessible_properties << property end end
Private Instance Methods
Internal: All properties of the class defined with define_property
.
Returns the the properties as Array or an empty Array.
# File lib/seatbelt/core/property.rb, line 90 def property_list @property_list ||= [] end