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

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

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 84

#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



70
71
72
73
# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 70

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 84

#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.



53
54
55
# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 53

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.



42
43
44
# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 42

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 84

#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 84

#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 84

#inherited(child) ⇒ Object

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



58
59
60
61
# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 58

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 84

#json(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 84

#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 84

#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 84

#map_columnsObject

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



47
48
49
# File 'lib/datastax_rails/attribute_methods/typecasting.rb', line 47

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 84

#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 84

#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 84

#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 84

#time_with_zone(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 84

#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 84

#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



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

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 84