Class: Paramore::Field
- Inherits:
-
Object
- Object
- Paramore::Field
- Defined in:
- lib/paramore/field.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ null: false, compact: false, default: nil, empty: false, required: true, }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #allow_empty? ⇒ Boolean
- #compact? ⇒ Boolean
- #default ⇒ Object
- #default? ⇒ Boolean
-
#initialize(given_type, null:, compact:, default:, empty:, required:) ⇒ Field
constructor
A new instance of Field.
- #nullable? ⇒ Boolean
- #required? ⇒ Boolean
- #type ⇒ Object
- #validate! ⇒ Object
- #wildly_keyed_hash? ⇒ Boolean
Constructor Details
#initialize(given_type, null:, compact:, default:, empty:, required:) ⇒ Field
Returns a new instance of Field.
13 14 15 16 17 18 19 20 |
# File 'lib/paramore/field.rb', line 13 def initialize(given_type, null:, compact:, default:, empty:, required:) @given_type = given_type @nullable = null @compact = compact @allow_empty = empty @default = default @required = required end |
Class Method Details
.wildly_keyed_hash?(hash) ⇒ Boolean
58 59 60 |
# File 'lib/paramore/field.rb', line 58 def self.wildly_keyed_hash?(hash) hash.keys.any? { |key| [Class, Module].include?(key.class) } end |
Instance Method Details
#allow_empty? ⇒ Boolean
26 27 28 |
# File 'lib/paramore/field.rb', line 26 def allow_empty? @allow_empty end |
#default ⇒ Object
34 35 36 |
# File 'lib/paramore/field.rb', line 34 def default @default.is_a?(Proc) ? @default.call : @default end |
#default? ⇒ Boolean
30 31 32 |
# File 'lib/paramore/field.rb', line 30 def default? !@default.nil? end |
#type ⇒ Object
46 47 48 |
# File 'lib/paramore/field.rb', line 46 def type @given_type end |
#validate! ⇒ Object
54 55 56 |
# File 'lib/paramore/field.rb', line 54 def validate! Paramore::Validate.run(self) end |
#wildly_keyed_hash? ⇒ Boolean
50 51 52 |
# File 'lib/paramore/field.rb', line 50 def wildly_keyed_hash? type.is_a?(Hash) && self.class.wildly_keyed_hash?(type) end |