Module: Attributor

Defined in:
lib/attributor/attribute.rb,
lib/attributor.rb,
lib/attributor/type.rb,
lib/attributor/version.rb,
lib/attributor/dumpable.rb,
lib/attributor/types/csv.rb,
lib/attributor/types/ids.rb,
lib/attributor/types/uri.rb,
lib/attributor/exceptions.rb,
lib/attributor/types/date.rb,
lib/attributor/types/hash.rb,
lib/attributor/types/time.rb,
lib/attributor/types/class.rb,
lib/attributor/types/float.rb,
lib/attributor/types/model.rb,
lib/attributor/dsl_compiler.rb,
lib/attributor/types/object.rb,
lib/attributor/types/regexp.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/families/numeric.rb,
lib/attributor/types/bigdecimal.rb,
lib/attributor/types/collection.rb,
lib/attributor/families/temporal.rb,
lib/attributor/hash_dsl_compiler.rb,
lib/attributor/types/file_upload.rb,
lib/attributor/attribute_resolver.rb,
lib/attributor/extras/field_selector.rb,
lib/attributor/extras/field_selector/parser.rb,
lib/attributor/extras/field_selector/transformer.rb

Overview

Abstract type for the ‘temporal’ family

Defined Under Namespace

Modules: Container, Dumpable, ExampleMixin, Type Classes: Attribute, AttributeResolver, AttributorException, BigDecimal, Boolean, CSV, Class, CoercionError, Collection, DSLCompiler, Date, DateTime, DeserializationError, DumpError, FakeParent, FieldSelector, FileUpload, Float, Hash, HashDSLCompiler, Ids, IncompatibleTypeError, Integer, InvalidDefinition, LoadError, Model, Numeric, Object, Regexp, String, Struct, Symbol, Tempfile, Temporal, Time, URI

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 =
'5.0.2'

Class Method Summary collapse

Class Method Details

.errorize_value(value) ⇒ Object



74
75
76
77
78
# File 'lib/attributor.rb', line 74

def self.errorize_value( value )
  inspection =value.inspect
  inspection = inspection[0..500]+ "...[truncated]" if inspection.size>500
  inspection
end

.humanize_context(context) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/attributor.rb', line 56

def self.humanize_context( context )
  return "" 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.message}"
  end
end

.resolve_type(attr_type, options = {}, constructor_block = nil) ⇒ Object

Parameters:

  • type (Class)

    The class of the type to resolve

Raises:



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, options={}, 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, options)
  end

  raise AttributorException.new("Type: #{attr_type} does not support anonymous generation") if constructor_block

  klass
end

.type_name(type) ⇒ Object



50
51
52
53
54
# File 'lib/attributor.rb', line 50

def self.type_name(type)
  return self.type_name(type.class) unless type.kind_of?(::Class)

  type.ancestors.find { |k| k.name && !k.name.empty? }.name
end