Module: Datacaster

Extended by:
Datacaster
Included in:
Datacaster
Defined in:
lib/datacaster.rb,
lib/datacaster/base.rb,
lib/datacaster/mixin.rb,
lib/datacaster/trier.rb,
lib/datacaster/utils.rb,
lib/datacaster/absent.rb,
lib/datacaster/caster.rb,
lib/datacaster/config.rb,
lib/datacaster/result.rb,
lib/datacaster/runner.rb,
lib/datacaster/checker.rb,
lib/datacaster/or_node.rb,
lib/datacaster/version.rb,
lib/datacaster/and_node.rb,
lib/datacaster/then_node.rb,
lib/datacaster/validator.rb,
lib/datacaster/comparator.rb,
lib/datacaster/predefined.rb,
lib/datacaster/around_node.rb,
lib/datacaster/hash_mapper.rb,
lib/datacaster/hash_schema.rb,
lib/datacaster/switch_node.rb,
lib/datacaster/transaction.rb,
lib/datacaster/transformer.rb,
lib/datacaster/array_schema.rb,
lib/datacaster/context_node.rb,
lib/datacaster/runtimes/base.rb,
lib/datacaster/runtimes/i18n.rb,
lib/datacaster/definition_dsl.rb,
lib/datacaster/i18n_values/key.rb,
lib/datacaster/substitute_i18n.rb,
lib/datacaster/i18n_values/base.rb,
lib/datacaster/i18n_values/scope.rb,
lib/datacaster/context_nodes/i18n.rb,
lib/datacaster/around_nodes/caster.rb,
lib/datacaster/message_keys_merger.rb,
lib/datacaster/context_nodes/pass_if.rb,
lib/datacaster/runtimes/user_context.rb,
lib/datacaster/runtimes/object_context.rb,
lib/datacaster/context_nodes/user_context.rb,
lib/datacaster/runtimes/structure_cleaner.rb,
lib/datacaster/context_nodes/errors_caster.rb,
lib/datacaster/context_nodes/object_context.rb,
lib/datacaster/context_nodes/i18n_keys_mapper.rb,
lib/datacaster/and_with_error_aggregation_node.rb,
lib/datacaster/context_nodes/structure_cleaner.rb

Defined Under Namespace

Modules: AroundNodes, Config, ContextNodes, I18nValues, Mixin, Predefined, Runtimes, SubstituteI18n, Transaction, Utils Classes: Absent, AndNode, AndWithErrorAggregationNode, AroundNode, ArraySchema, Base, Caster, Checker, Comparator, ContextNode, DefinitionDSL, HashMapper, HashSchema, MessageKeysMerger, OrNode, Result, Runner, SwitchNode, ThenNode, Transformer, Trier, Validator

Constant Summary collapse

VERSION =
"4.1.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ErrorResult(object) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/datacaster/result.rb', line 90

def self.ErrorResult(object)
  if object.is_a?(Result)
    raise "Can't create error result from valid #{object.inspect}" if object.valid?
    object
  else
    Result.new(false, object)
  end
end

.ValidResult(object) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/datacaster/result.rb', line 81

def self.ValidResult(object)
  if object.is_a?(Result)
    raise "Can't create valid result from error #{object.inspect}" unless object.valid?
    object
  else
    Result.new(true, object)
  end
end

Instance Method Details

#absentObject



23
24
25
# File 'lib/datacaster.rb', line 23

def absent
  Datacaster::Absent.instance
end

#choosy_schema(i18n_scope: nil, &block) ⇒ Object



15
16
17
# File 'lib/datacaster.rb', line 15

def choosy_schema(i18n_scope: nil, &block)
  ContextNodes::StructureCleaner.new(build_schema(i18n_scope: i18n_scope, &block), :remove)
end

#instance?(object) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/datacaster.rb', line 27

def instance?(object)
  object.is_a?(Mixin)
end

#partial_schema(i18n_scope: nil, &block) ⇒ Object



19
20
21
# File 'lib/datacaster.rb', line 19

def partial_schema(i18n_scope: nil, &block)
  ContextNodes::StructureCleaner.new(build_schema(i18n_scope: i18n_scope, &block), :pass)
end

#schema(i18n_scope: nil, &block) ⇒ Object



11
12
13
# File 'lib/datacaster.rb', line 11

def schema(i18n_scope: nil, &block)
  ContextNodes::StructureCleaner.new(build_schema(i18n_scope: i18n_scope, &block), :fail)
end