Module: RailsDictionary::ActiveRecordExtension::ClassMethods
- Defined in:
- lib/rails_dictionary/active_record_extension.rb
Instance Method Summary collapse
-
#acts_as_dict_slave(ops = {}) ⇒ Object
(also: #acts_as_dict_consumer)
Ex: acts_as_dict_slave :add => :category :except - remove dict mapping column :add - add dict mapping column :locale - add and initialize class attribute default_dict_locale.
-
#acts_as_dict_type ⇒ Object
TODO: move macro define in each module file See Usage in readme.doc.
- #acts_as_dictionary ⇒ Object
Instance Method Details
#acts_as_dict_slave(ops = {}) ⇒ Object Also known as: acts_as_dict_consumer
Ex: acts_as_dict_slave :add => :category :except - remove dict mapping column :add - add dict mapping column :locale - add and initialize class attribute default_dict_locale
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rails_dictionary/active_record_extension.rb', line 34 def acts_as_dict_slave(ops={}) include RailsDictionary::ActsAsDictSlave class_attribute :default_dict_locale, :instance_writer => false cattr_accessor :dict_mapping_columns, :instance_writer => false self.default_dict_locale = ops[:locale] if ops[:locale] self.dict_mapping_columns = dict_columns(ops) unless dict_mapping_columns.nil? add_dynamic_column_method end end |
#acts_as_dict_type ⇒ Object
TODO: move macro define in each module file See Usage in readme.doc.
10 11 12 13 14 15 16 17 18 |
# File 'lib/rails_dictionary/active_record_extension.rb', line 10 def acts_as_dict_type has_many :dictionaries validates_uniqueness_of :name after_save :delete_all_caches after_destroy :delete_all_caches include RailsDictionary::ActsAsDictType end |
#acts_as_dictionary ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/rails_dictionary/active_record_extension.rb', line 20 def acts_as_dictionary belongs_to :dict_type after_save :delete_dicts_cache after_destroy :delete_dicts_cache scope :dict_type_name_eq, ->(name) { joins(:dict_type).where({ "dict_types.name" => name }) } include RailsDictionary::ActsAsDictionary end |