Class: ActiveRecordYaml::Model
- Inherits:
-
Object
- Object
- ActiveRecordYaml::Model
- Extended by:
- ActiveModel::Naming
- Defined in:
- lib/active_record_yaml/model.rb
Class Method Summary collapse
- .all ⇒ Object
- .count ⇒ Object
- .data_dir ⇒ Object
- .data_filename ⇒ Object
- .first ⇒ Object
- .items ⇒ Object
- .last ⇒ Object
- .method_missing(m, *args, &block) ⇒ Object
- .respond_to_missing?(m, include_private = false) ⇒ Boolean
Class Method Details
.all ⇒ Object
5 6 7 |
# File 'lib/active_record_yaml/model.rb', line 5 def self.all items end |
.count ⇒ Object
17 18 19 |
# File 'lib/active_record_yaml/model.rb', line 17 def self.count items.length end |
.data_dir ⇒ Object
41 42 43 |
# File 'lib/active_record_yaml/model.rb', line 41 def self.data_dir Rails.root.join("config", "data") end |
.data_filename ⇒ Object
37 38 39 |
# File 'lib/active_record_yaml/model.rb', line 37 def self.data_filename data_dir.join("#{model_name.plural}.yml") end |
.first ⇒ Object
9 10 11 |
# File 'lib/active_record_yaml/model.rb', line 9 def self.first items.first end |
.items ⇒ Object
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 |
.last ⇒ Object
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
33 34 35 |
# File 'lib/active_record_yaml/model.rb', line 33 def self.respond_to_missing?(m, include_private = false) super end |