Module: DatastaxRails::AttributeMethods::Typecasting::ClassMethods

Defined in:
lib/datastax_rails/attribute_methods/typecasting.rb

Overview

:nodoc:

Attribute Types collapse

Instance Method Summary collapse

Instance Method Details

#array(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 81

#binary(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


67
68
69
70
# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 67

def binary(name, options = {})
  options.reverse_merge!(lazy: true)
  attribute(name, options.update(type: :binary))
end

#boolean(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 81

#column_defaultsObject

Returns a hash where the keys are column names and the values are default values when instantiating the DSR object for this table.


50
51
52
# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 50

def column_defaults
  @column_defaults ||= Hash[columns.map { |c| [c.name.to_s, c.default] }]
end

#columns_hashObject

Provide some measure of compatibility with things that expect this from ActiveRecord.


39
40
41
# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 39

def columns_hash
  attribute_definitions
end

#date(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 81

#datetime(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 81

#double(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 81

#float(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 81

#inherited(child) ⇒ Object

We need to ensure that inherited classes get their own attribute definitions.


55
56
57
58
# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 55

def inherited(child)
  super
  child.attribute_definitions = attribute_definitions.dup
end

#integer(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 81

#list(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 81

#long(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 81

#map(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 81

#map_columnsObject

Gives you all of the map columns (useful for detecting dynamic columns)


44
45
46
# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 44

def map_columns
  @map_columns ||= attribute_definitions.values.select { |c| c.type == :map }
end

#set(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 81

#string(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 81

#text(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 81

#time(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 81

#timestamp(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 81

#timestamps(options = {}) ⇒ Object

Declare the timestamps attribute type method. Creates both the created_at and updated_at attributes with type time.

Parameters:

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


76
77
78
79
# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 76

def timestamps(options = {})
  attribute(:created_at, options.update(type: :timestamp))
  attribute(:updated_at, options.update(type: :timestamp))
end

#uuid(name, options = {}) ⇒ Object

Declare an attribute of the given type

Parameters:

  • name (Symbol)

    the name of the attribute to create

  • options (Hash) (defaults to: {})

    the options to use in setting up the attribute


# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 81