Class: ReeMapper::Field
- Inherits:
-
Object
- Object
- ReeMapper::Field
- Defined in:
- lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb
Constant Summary collapse
- NO_DEFAULT =
Object.new.freeze
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#fields_filter ⇒ Object
readonly
Returns the value of attribute fields_filter.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#from_as_str ⇒ Object
readonly
Returns the value of attribute from_as_str.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#name_as_instance_var_name ⇒ Object
readonly
Returns the value of attribute name_as_instance_var_name.
-
#name_as_str ⇒ Object
readonly
Returns the value of attribute name_as_str.
-
#null ⇒ Object
readonly
Returns the value of attribute null.
-
#optional ⇒ Object
readonly
Returns the value of attribute optional.
-
#roles ⇒ Object
readonly
Returns the value of attribute roles.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #has_default? ⇒ Boolean
- #has_role?(role) ⇒ Boolean
-
#initialize(type, name = nil, from: nil, doc: nil, optional: false, null: false, role: nil, default: NO_DEFAULT, only: nil, except: nil, location: nil) ⇒ Field
constructor
A new instance of Field.
Constructor Details
#initialize(type, name = nil, from: nil, doc: nil, optional: false, null: false, role: nil, default: NO_DEFAULT, only: nil, except: nil, location: nil) ⇒ Field
Returns a new instance of Field.
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 50 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb', line 25 def initialize(type, name = nil, from: nil, doc: nil, optional: false, null: false, role: nil, default: NO_DEFAULT, only: nil, except: nil, location: nil) @type = type @name = name @from = from || name @doc = doc @optional = optional @null = null @roles = Array(role) @default = default @fields_filter = ReeMapper::FieldsFilter.build(only, except) @name_as_str = @name.to_s @name_as_instance_var_name = :"@#{@name}" @from_as_str = @from.to_s @location = location if @location @location = @location .sub(Ree.root_dir, ".") .sub(/:in.+/, "") end raise ArgumentError, 'required fields do not support defaults' if has_default? && !optional end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
4 5 6 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb', line 4 def default @default end |
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
4 5 6 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb', line 4 def doc @doc end |
#fields_filter ⇒ Object (readonly)
Returns the value of attribute fields_filter.
4 5 6 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb', line 4 def fields_filter @fields_filter end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
4 5 6 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb', line 4 def from @from end |
#from_as_str ⇒ Object (readonly)
Returns the value of attribute from_as_str.
4 5 6 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb', line 4 def from_as_str @from_as_str end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
4 5 6 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb', line 4 def location @location end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb', line 4 def name @name end |
#name_as_instance_var_name ⇒ Object (readonly)
Returns the value of attribute name_as_instance_var_name.
4 5 6 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb', line 4 def name_as_instance_var_name @name_as_instance_var_name end |
#name_as_str ⇒ Object (readonly)
Returns the value of attribute name_as_str.
4 5 6 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb', line 4 def name_as_str @name_as_str end |
#null ⇒ Object (readonly)
Returns the value of attribute null.
4 5 6 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb', line 4 def null @null end |
#optional ⇒ Object (readonly)
Returns the value of attribute optional.
4 5 6 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb', line 4 def optional @optional end |
#roles ⇒ Object (readonly)
Returns the value of attribute roles.
4 5 6 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb', line 4 def roles @roles end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb', line 4 def type @type end |
Instance Method Details
#has_default? ⇒ Boolean
53 54 55 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb', line 53 def has_default? default != NO_DEFAULT end |
#has_role?(role) ⇒ Boolean
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/field.rb', line 58 def has_role?(role) return true if roles.empty? return false if role.nil? if role.is_a?(Array) role.any? { roles.include?(_1) } else roles.include?(role) end end |