Class: CmisServer::Property
- Inherits:
-
Object
- Object
- CmisServer::Property
- Defined in:
- lib/cmis_server/property.rb
Instance Attribute Summary collapse
-
#property_definition ⇒ Object
readonly
Returns the value of attribute property_definition.
Instance Method Summary collapse
-
#initialize(property_definition, value = nil, object = nil) ⇒ Property
constructor
A new instance of Property.
- #set_default ⇒ Object
- #value ⇒ Object
- #value=(v) ⇒ Object
Constructor Details
#initialize(property_definition, value = nil, object = nil) ⇒ Property
Returns a new instance of Property.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cmis_server/property.rb', line 29 def initialize(property_definition, value=nil, object=nil) # Support des deux formes d'arguments if property_definition.is_a?(Hash) && property_definition[:id] # Forme avec arguments nommés : Property.new(id: 'cmis:name', value: 'foo') # Déterminer le type en fonction de la valeur type_class = case property_definition[:value] when String then String when Integer then Integer when Float then Float when Time, DateTime then DateTime when TrueClass, FalseClass then OpenStruct.new(name: 'Boolean') else String end # Créer un type object si ce n'est pas déjà un OpenStruct type = type_class.is_a?(OpenStruct) ? type_class : OpenStruct.new(name: type_class.name) @property_definition = OpenStruct.new( id: property_definition[:id], type: type, query_name: property_definition[:id], display_name: property_definition[:id].split(':').last.humanize, local_name: property_definition[:id].split(':').last, value: nil # Les PropertyDefinition n'ont pas de value fixe ) @value = property_definition[:value] @object = property_definition[:object] else # Forme classique : Property.new(property_def, value, object) @object =object @property_definition=property_definition @value =value end end |
Instance Attribute Details
#property_definition ⇒ Object (readonly)
Returns the value of attribute property_definition.
7 8 9 |
# File 'lib/cmis_server/property.rb', line 7 def property_definition @property_definition end |
Instance Method Details
#set_default ⇒ Object
25 26 27 |
# File 'lib/cmis_server/property.rb', line 25 def set_default @value||=@property_definition.default_value.dup end |
#value ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/cmis_server/property.rb', line 17 def value if self.property_definition.respond_to?(:value) && self.property_definition.value self.property_definition.value_for(@object) else @value end end |
#value=(v) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/cmis_server/property.rb', line 9 def value=(v) if self.property_definition.value nil else @value=v end end |