Module: OdataDuty::Property
- Defined in:
- lib/odata_duty/property.rb,
lib/odata_duty/property/single_prop.rb,
lib/odata_duty/property/collection_prop.rb
Defined Under Namespace
Classes: CollectionProp, SingleProp
Constant Summary collapse
- MUTABILITIES =
%i[read_write immutable non_insertable computed].freeze
- MUTABILITIES_LIST =
MUTABILITIES.map(&:inspect).join(', ').freeze
- NAME_REGEXP =
Regexp.new('\A(?:\p{L}|_)(?:[\p{L}\p{Nd}_])*\z').freeze
- CORE_ANNOTATION_TERMS =
{ computed: 'Org.OData.Core.V1.Computed', immutable: 'Org.OData.Core.V1.Immutable' }.freeze
Class Method Summary collapse
- .computed_to_mutability(name, computed, mutability) ⇒ Object
- .new(name, type = String, line__defined__at: nil, nullable: true, method: nil, computed: :unset, mutability: :unset, description: nil) ⇒ Object
- .resolve_description(owner_name, description) ⇒ Object
- .resolve_mutability(name, computed, mutability) ⇒ Object
- .valid_name?(name) ⇒ Boolean
Class Method Details
.computed_to_mutability(name, computed, mutability) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/odata_duty/property.rb', line 47 def self.computed_to_mutability(name, computed, mutability) unless mutability == :unset raise ArgumentError, "#{name}: pass either `mutability:` or `computed:`, not both \u2014 they control " \ 'the same axis' end computed ? :computed : :read_write end |
.new(name, type = String, line__defined__at: nil, nullable: true, method: nil, computed: :unset, mutability: :unset, description: nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/odata_duty/property.rb', line 10 def self.new(name, type = String, line__defined__at: nil, nullable: true, method: nil, computed: :unset, mutability: :unset, description: nil) unless valid_name?(name) raise InvalidNCNamesError, "\"#{name}\" is not a valid property name" end prop_class = type.instance_of?(Array) ? CollectionProp : SingleProp prop_class.new(name, type, line__defined__at: line__defined__at, nullable: nullable, method: method, mutability: resolve_mutability(name, computed, mutability), description: resolve_description(name, description)) end |
.resolve_description(owner_name, description) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/odata_duty/property.rb', line 25 def self.resolve_description(owner_name, description) return if description.nil? str = description.to_str if description.respond_to?(:to_str) unless str.is_a?(String) && str.match?(/\S/) raise InvalidDescriptionError, "#{owner_name}: description must be a non-empty string" end str end |
.resolve_mutability(name, computed, mutability) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/odata_duty/property.rb', line 37 def self.resolve_mutability(name, computed, mutability) mutability = computed_to_mutability(name, computed, mutability) unless computed == :unset mutability = :read_write if mutability == :unset return mutability if MUTABILITIES.include?(mutability) raise ArgumentError, "#{name}: invalid mutability #{mutability.inspect}, " \ "must be one of #{MUTABILITIES_LIST}" end |
.valid_name?(name) ⇒ Boolean
58 59 60 |
# File 'lib/odata_duty/property.rb', line 58 def self.valid_name?(name) name.match?(NAME_REGEXP) end |