Class: ActiveWindow::ActiveColumn

Inherits:
Object
  • Object
show all
Defined in:
lib/active_window/active_column.rb

Overview

ActiveColumn is used to define columns for ActiveTreeStore

Constant Summary collapse

ClassesToSymbols =
{
  TrueClass     => :boolean,
  FalseClass    => :boolean,
  String        => :string,
  Time          => :datetime,
  Date          => :datetime,
  Fixnum        => :integer,
  Bignum        => :integer,
  Integer       => :integer,
  Float         => :float,
  Gdk::Pixbuf   => :image
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, opts = {}) ⇒ ActiveColumn

Returns a new instance of ActiveColumn.



43
44
45
46
47
48
49
# File 'lib/active_window/active_column.rb', line 43

def initialize(id, name, opts={})
  self.id = id
  self.name = name
  @virtual = opts[:virtual] == true ? true : false
  @visible = opts[:visible] == false ? false : true
  #puts 'new column: %s %s' % [self.class, name]
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.create(id, name, klass = :string, opts = {}) ⇒ Object

column: ActiveRecord::ConnectionAdapters::MysqlColumn



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/active_window/active_column.rb', line 29

def self.create(id, name, klass=:string, opts={})
  klass = ClassesToSymbols[klass] if klass.is_a?(Class)
  subclass = case klass # ignore warning this creates
    when :string;         ActiveTextColumn
    when :datetime;       ActiveDateColumn
    when :integer;        ActiveIntegerColumn
    when :float;          ActiveFloatColumn
    when :boolean;        ActiveToggleColumn
    when :image;          ActiveImageColumn
    else; self
  end
  return subclass.new(id, name.to_s, opts)
end

Instance Method Details

#data_classObject

return the class of the value held for this column in the model



73
74
75
# File 'lib/active_window/active_column.rb', line 73

def data_class
  Object
end

#data_value(ar_object) ⇒ Object

given an active record object, return the attribute value that corresponds to this column. the returned value must match the class returned in data_class. so, you might have to do some conversion.



81
82
83
# File 'lib/active_window/active_column.rb', line 81

def data_value(ar_object)
  ar_object.send(self.name)
end

#hide!Object



55
56
57
# File 'lib/active_window/active_column.rb', line 55

def hide!
  @visible = false
end

#rendererObject



68
69
70
# File 'lib/active_window/active_column.rb', line 68

def renderer
  raise "There is no way to render #{name} yet."
end

#viewObject

return a Gtk::TreeViewColumn appropriate for showing this column



64
65
66
# File 'lib/active_window/active_column.rb', line 64

def view
  raise "There is no way to show #{name} yet."
end

#virtual?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/active_window/active_column.rb', line 51

def virtual?
  @virtual
end

#visible?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/active_window/active_column.rb', line 59

def visible?
  @visible
end