Class: Semr::Rails::ModelInflector
- Inherits:
-
Object
- Object
- Semr::Rails::ModelInflector
- Defined in:
- lib/semr/rails/model_inflector.rb
Instance Attribute Summary collapse
-
#inflections ⇒ Object
readonly
Returns the value of attribute inflections.
-
#models ⇒ Object
readonly
Returns the value of attribute models.
Class Method Summary collapse
Instance Method Summary collapse
- #and ⇒ Object
-
#initialize(models) ⇒ ModelInflector
constructor
A new instance of ModelInflector.
- #to_a ⇒ Object
- #with_plurals ⇒ Object
- #with_synonyms ⇒ Object
Constructor Details
#initialize(models) ⇒ ModelInflector
Returns a new instance of ModelInflector.
12 13 14 15 |
# File 'lib/semr/rails/model_inflector.rb', line 12 def initialize(models) @models = models @inflections = models.collect{|klass| klass.name.to_s } end |
Instance Attribute Details
#inflections ⇒ Object (readonly)
Returns the value of attribute inflections.
10 11 12 |
# File 'lib/semr/rails/model_inflector.rb', line 10 def inflections @inflections end |
#models ⇒ Object (readonly)
Returns the value of attribute models.
10 11 12 |
# File 'lib/semr/rails/model_inflector.rb', line 10 def models @models end |
Class Method Details
.all ⇒ Object
5 6 7 |
# File 'lib/semr/rails/model_inflector.rb', line 5 def all ModelInflector.new ::ActiveRecord::Base.send(:subclasses) end |
Instance Method Details
#and ⇒ Object
41 42 43 |
# File 'lib/semr/rails/model_inflector.rb', line 41 def and self end |
#to_a ⇒ Object
45 46 47 |
# File 'lib/semr/rails/model_inflector.rb', line 45 def to_a @inflections end |
#with_plurals ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/semr/rails/model_inflector.rb', line 17 def with_plurals plural_inflections = [] @inflections.each do |inflection| root = Dictionary.find_root(inflection) pluralized_inflection = inflection.pluralize Dictionary.register(pluralized_inflection, root) plural_inflections << pluralized_inflection end @inflections.unshift plural_inflections #@inflections << plural_inflections - need to test, plurals screws up regex @inflections.flatten! self end |
#with_synonyms ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/semr/rails/model_inflector.rb', line 31 def with_synonyms @models.each do |model| model.synonyms.each do |synonym| Dictionary.register(synonym, model.name) @inflections << synonym end unless model.synonyms.nil? || model.synonyms.empty? end self end |