Module: MobilityTyped::Writer

Extended by:
Mobility::Plugin
Defined in:
lib/mobility_typed/writer.rb

Defined Under Namespace

Classes: TypeError

Constant Summary collapse

TYPES_MAP =
{
  String => :string,
  Integer => :integer,
  Float => :float,
  TrueClass => :bool,
  FalseClass => :bool,
  Array => :array,
  Hash => :hash
}.freeze

Class Method Summary collapse

Class Method Details

.check_type(name, type) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/mobility_typed/writer.rb', line 52

def self.check_type(name, type)
  "  if !value.nil? \n    value_type = MobilityTyped::Writer.value_type(value)\n    if value_type != :\#{type}        \n      raise MobilityTyped::Writer::TypeError, \"\#{name}= called with \\\#{value_type}, \#{type} expected\"\n    end\n  end\n  EOL\nend\n"

.setup_sourceObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mobility_typed/writer.rb', line 40

def self.setup_source
  "    return super(value) if options[:super]\n    if (locale &&= locale.to_sym)\n      \#{'Mobility.enforce_available_locales!(locale)' if I18n.enforce_available_locales}\n      options[:locale] = true\n    else\n      locale = Mobility.locale\n    end\n  EOL\nend\n"

.value_type(value) ⇒ Object



63
64
65
# File 'lib/mobility_typed/writer.rb', line 63

def self.value_type(value)
  TYPES_MAP[value.class] || value.class
end