Module: Zena::Use::NestedAttributesAlias::ClassMethods
- Defined in:
- lib/zena/use/nested_attributes_alias.rb
Overview
ModelMethods
Instance Method Summary collapse
-
#nested_attr_alias_list ⇒ Object
Return the list of all ordered routes, including routes defined in the superclass.
- #nested_attributes_alias(definitions) ⇒ Object
-
#nested_model_names_for_alias(attribute) ⇒ Object
Same as model method but will not take Proc type resolution.
Instance Method Details
#nested_attr_alias_list ⇒ Object
Return the list of all ordered routes, including routes defined in the superclass
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/zena/use/nested_attributes_alias.rb', line 148 def nested_attr_alias_list @@_nested_attr_alias_list[self] ||= if superclass.respond_to?(:nested_attributes_alias) # merge with superclass attributes list = superclass.nested_attr_alias_list.dup (@@_nested_attr_alias[self] || []).each do |regex, method| list.reject! do |k, v| # allow new rule to overwrite parent rule k == regex end list << [regex, method] end list else # top class, nothing to inherit @@_nested_attr_alias[self] || [] end end |
#nested_attributes_alias(definitions) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/zena/use/nested_attributes_alias.rb', line 166 def nested_attributes_alias(definitions) list = (@@_nested_attr_alias[self] ||= []) definitions.each do |regexp, target| # allow new rule to overwrite rule previously defined list.reject! {|k, v| k == regexp} if target.kind_of?(String) target = target.split(".") end list << [regexp, target] end end |
#nested_model_names_for_alias(attribute) ⇒ Object
Same as model method but will not take Proc type resolution. This could be used by RubyLess to resolve ‘title’ into ==> version ==> title we will see…
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/zena/use/nested_attributes_alias.rb', line 182 def nested_model_names_for_alias(attribute) attribute = attribute.to_s nested_model_names = nil nested_attr_alias_list.each do |regexp, target| if attribute =~ regexp if target.kind_of?(Proc) # ignore else nested_model_names = target + [$1] break end end end nested_model_names end |