Module: Seatbelt::Property::ClassMethods
- Included in:
- Interface
- Defined in:
- lib/seatbelt/core/property.rb
Instance Method Summary collapse
-
#accessible_properties ⇒ Object
Public: All properties that are marked as accessible.
-
#define_properties(*properties) ⇒ Object
Public: Mass defining of properties.
-
#define_property(*args) ⇒ Object
Public: Defines an API property.
-
#property_accessible(*properties) ⇒ Object
Public: Defines one or more properties to be mass assignable due the #properties= setter method.
Instance Method Details
#accessible_properties ⇒ Object
Public: All properties that are marked as accessible.
Returns the property list or an empty Array.
56 57 58 |
# File 'lib/seatbelt/core/property.rb', line 56 def accessible_properties @accessible_properties ||= [] end |
#define_properties(*properties) ⇒ Object
Public: Mass defining of properties.
See #define_property for details
-
properties - A list of property names to define.
49 50 51 |
# File 'lib/seatbelt/core/property.rb', line 49 def define_properties(*properties) properties.each { |property| define_property(property) } end |
#define_property(*args) ⇒ Object
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
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/seatbelt/core/property.rb', line 24 def define_property(*args) if @scope.eql?(:class) raise Seatbelt::Errors::PropertyOnClassLevelDefinedError end hsh = {} = args. accessible = .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 |
#property_accessible(*properties) ⇒ Object
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.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# 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 |