Module: Attributor
- Defined in:
- lib/attributor/attribute.rb,
lib/attributor.rb,
lib/attributor/type.rb,
lib/attributor/version.rb,
lib/attributor/types/csv.rb,
lib/attributor/types/ids.rb,
lib/attributor/exceptions.rb,
lib/attributor/types/date.rb,
lib/attributor/types/hash.rb,
lib/attributor/types/time.rb,
lib/attributor/types/float.rb,
lib/attributor/types/model.rb,
lib/attributor/dsl_compiler.rb,
lib/attributor/types/object.rb,
lib/attributor/types/string.rb,
lib/attributor/types/struct.rb,
lib/attributor/types/symbol.rb,
lib/attributor/example_mixin.rb,
lib/attributor/types/boolean.rb,
lib/attributor/types/integer.rb,
lib/attributor/types/tempfile.rb,
lib/attributor/types/container.rb,
lib/attributor/types/date_time.rb,
lib/attributor/types/bigdecimal.rb,
lib/attributor/types/collection.rb,
lib/attributor/types/file_upload.rb,
lib/attributor/attribute_resolver.rb
Overview
Represents an unordered collection of attributes
Defined Under Namespace
Modules: Container, ExampleMixin, Type Classes: Attribute, AttributeResolver, AttributorException, BigDecimal, Boolean, CSV, CoercionError, Collection, DSLCompiler, Date, DateTime, DeserializationError, DumpError, FakeParent, FileUpload, Float, Hash, Ids, IncompatibleTypeError, Integer, LoadError, Model, Object, String, Struct, Symbol, Tempfile, Time
Constant Summary collapse
- SEPARATOR =
hierarchical separator string for composing human readable attributes
'.'.freeze
- DEFAULT_ROOT_CONTEXT =
['$'].freeze
- MODULE_PREFIX =
"Attributor\:\:".freeze
- MODULE_PREFIX_REGEX =
Regexp.new(MODULE_PREFIX)
- VERSION =
"2.6.0"
Class Method Summary collapse
- .errorize_value(value) ⇒ Object
- .humanize_context(context) ⇒ Object
- .resolve_type(attr_type, options = {}, constructor_block = nil) ⇒ Object
Class Method Details
.errorize_value(value) ⇒ Object
68 69 70 71 72 |
# File 'lib/attributor.rb', line 68 def self.errorize_value( value ) inspection =value.inspect inspection = inspection[0..500]+ "...[truncated]" if inspection.size>500 inspection end |
.humanize_context(context) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/attributor.rb', line 50 def self.humanize_context( context ) raise "NIL CONTEXT PASSED TO HUMANZE!!" unless context if context.kind_of? ::String context = Array(context) end unless context.is_a? Enumerable raise "INVALID CONTEXT!!! (got: #{context.inspect})" end begin return context.join('.') rescue Exception => e raise "Error creating context string: #{e.}" end end |
.resolve_type(attr_type, options = {}, constructor_block = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/attributor.rb', line 30 def self.resolve_type(attr_type, ={}, constructor_block=nil) if attr_type < Attributor::Type klass = attr_type else name = attr_type.name.split("::").last # TOO EXPENSIVE? klass = const_get(name) if const_defined?(name) raise AttributorException.new("Could not find class with name #{name}") unless klass raise AttributorException.new("Could not find attribute type for: #{name} [klass: #{klass.name}]") unless klass < Attributor::Type end if klass.constructable? return klass.construct(constructor_block, ) end raise AttributorException.new("Type: #{attr_type} does not support anonymous generation") if constructor_block klass end |