Class: ActiveRecord::SJISBase

Inherits:
Base
  • Object
show all
Defined in:
lib/custom_active_record/sjis_base.rb

Direct Known Subclasses

NOIDBase, PluralsPKeysSJISBase

Constant Summary collapse

@@picture_dir =

ClassName.exist? search all record if exist return true ClassName.exist?(:name => “hanako”) search hanako in field name ClassName.exist?(:name => “hanako”, :age => 18)

nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.calculate(operation, column_name, options = {}) ⇒ Object



119
120
121
# File 'lib/custom_active_record/sjis_base.rb', line 119

def self.calculate(operation, column_name, options = {})
  super(operation, column_name, options.to_mssql_encode)
end

.delete(id) ⇒ Object



78
79
80
81
# File 'lib/custom_active_record/sjis_base.rb', line 78

def self.delete(id)
  delete_all([ "#{connection.quote_column_name(primary_key)} IN (?)", id ],
             :sjis)
end

.delete_all(conditions, encode = :utf8) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/custom_active_record/sjis_base.rb', line 107

def self.delete_all(conditions, encode = :utf8)
  if encode == :utf8
    super(conditions.to_mssql_encode)
  else
    super(conditions)
  end
end

.destroy_all(conditions) ⇒ Object



103
104
105
# File 'lib/custom_active_record/sjis_base.rb', line 103

def self.destroy_all(conditions)
  super(conditions.to_mssql_encode)
end

.exist?(conditions = nil) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/custom_active_record/sjis_base.rb', line 40

def self.exist?(conditions = nil)
  if conditions.nil?
    return !self.find(:first).nil?
  end

  if conditions.is_a?(String) or conditions.is_a?(Array)
    return !self.find(:first, :conditions => conditions).nil?
  end

  if conditions.is_a?(Hash)
    where = ""
    where_array = []
    first = true

    conditions.each do |column_name, value|
      where << " and " unless first

      if value.is_a?(Array)
        q_array = []

        value.each do |v1|
          q_array.push("?")
        end

        where << " [#{column_name}] in (#{q_array.join(',')})"
        where_array += value
      else
        where << " [#{column_name}] in (?) "
        where_array.push(value)
      end

      first = false
    end

    !self.find(:first, :conditions => [where].concat(where_array)).nil?
  end
end

.find(*args) ⇒ Object



91
92
93
# File 'lib/custom_active_record/sjis_base.rb', line 91

def self.find(*args)
  super(*(args.to_mssql_encode))
end

.set_picture_dir(value) ⇒ Object



36
37
38
# File 'lib/custom_active_record/sjis_base.rb', line 36

def self.set_picture_dir(value)
  @@picture_dir = value
end

.set_primary_key(value = nil, &block) ⇒ Object



87
88
89
# File 'lib/custom_active_record/sjis_base.rb', line 87

def self.set_primary_key(value = nil, &block)
  define_attr_method :primary_key, value.to_mssql_encode, &block
end

.set_table_name(value = nil, &block) ⇒ Object



83
84
85
# File 'lib/custom_active_record/sjis_base.rb', line 83

def self.set_table_name(value = nil, &block)
  super(value.to_mssql_encode, &block)
end

.update_all(conditions) ⇒ Object



115
116
117
# File 'lib/custom_active_record/sjis_base.rb', line 115

def self.update_all(conditions)
  super(conditions.to_mssql_encode)
end

Instance Method Details

#[](attr_name) ⇒ Object



123
124
125
# File 'lib/custom_active_record/sjis_base.rb', line 123

def [](attr_name)
  super(attr_name.to_mssql_encode).to_display_encode
end

#[]=(attr_name, value) ⇒ Object



127
128
129
# File 'lib/custom_active_record/sjis_base.rb', line 127

def []=(attr_name, value)
  super(attr_name.to_mssql_encode, value.to_mssql_encode)
end

#attributes=(new_attributes, guard_protected_attributes = true) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/custom_active_record/sjis_base.rb', line 95

def attributes=(new_attributes, guard_protected_attributes = true)
  return if new_attributes.nil?

  new_attributes.to_mssql_encode.each do |k, v|
    write_attribute(k, v)
  end
end