Class: ActiveRecordYaml::Model

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Defined in:
lib/active_record_yaml/model.rb

Class Method Summary collapse

Class Method Details

.allObject



5
6
7
# File 'lib/active_record_yaml/model.rb', line 5

def self.all
  items
end

.countObject



17
18
19
# File 'lib/active_record_yaml/model.rb', line 17

def self.count
  items.length
end

.data_dirObject



41
42
43
# File 'lib/active_record_yaml/model.rb', line 41

def self.data_dir
  Rails.root.join("config", "data")
end

.data_filenameObject



37
38
39
# File 'lib/active_record_yaml/model.rb', line 37

def self.data_filename
  data_dir.join("#{model_name.plural}.yml")
end

.firstObject



9
10
11
# File 'lib/active_record_yaml/model.rb', line 9

def self.first
  items.first
end

.itemsObject



21
22
23
24
# File 'lib/active_record_yaml/model.rb', line 21

def self.items
  data = File.read(data_filename)
  YAML.load(data).map { |x| OpenStruct.new(x) }
end

.lastObject



13
14
15
# File 'lib/active_record_yaml/model.rb', line 13

def self.last
  items.last
end

.method_missing(m, *args, &block) ⇒ Object



26
27
28
29
30
31
# File 'lib/active_record_yaml/model.rb', line 26

def self.method_missing(m, *args, &block)
  key = ActiveSupport::Inflector.singularize(m)
  all.map(&:"#{key}")
rescue
  super
end

.respond_to_missing?(m, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/active_record_yaml/model.rb', line 33

def self.respond_to_missing?(m, include_private = false)
  super
end