Module: Sequel::Plugins::ArMethods::ClassMethods

Defined in:
lib/clevic/ar_methods.rb

Instance Method Summary collapse

Instance Method Details

#count_ar(*args) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
# File 'lib/clevic/ar_methods.rb', line 117

def count_ar( *args )
  options = args.extract_options!
  attribute = args.first

  dataset = dataset.translate( options )

  unless attribute.nil?
    dataset = dataset.select( attribute )
  end
  dataset.count
end

#find_ar(*args) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/clevic/ar_methods.rb', line 92

def find_ar( *args )
  # copied from ActiveRecord::Base.find
  options = args.extract_options!
  #~ validate_find_options(options)
  #~ set_readonly_option!(options)

  case args.first
    when :first
      dataset.translate(options).first

    when :last
      dataset.translate(options).last

    when :all
      dataset.translate(options).all

    else
      if args.size == 1
        dataset.translate(options).filter( :id.qualify( table_name ) => args.first ).first
      else
        dataset.translate(options).filter( :id.qualify( table_name ) => args ).all
      end
  end
end

#inherited(subclass) ⇒ Object

Copy the necessary class instance variables to the subclass.



84
85
86
# File 'lib/clevic/ar_methods.rb', line 84

def inherited(subclass)
  super
end

#translate(options) ⇒ Object



88
89
90
# File 'lib/clevic/ar_methods.rb', line 88

def translate( options )
  dataset.translate( options )
end