Module: Flex::ActiveModel::Attachment
- Defined in:
- lib/flex/active_model/attachment.rb
Instance Method Summary collapse
-
#attribute_attachment(*args) ⇒ Object
defines accessors for <attachment_field_name> if you omit the arguments it uses :attachment as the <attachment_field_name> you can also pass other properties that will be merged with the default property for attachment this will automatically add a :<attachment_field_name>_scope scope which will add all the meta fields (title, author, …) to the returned fields, exluding the <attachment_field_name> field itself and including all the other attributes declared before it.
Instance Method Details
#attribute_attachment(*args) ⇒ Object
defines accessors for <attachment_field_name> if you omit the arguments it uses :attachment as the <attachment_field_name> you can also pass other properties that will be merged with the default property for attachment this will automatically add a :<attachment_field_name>_scope scope which will add all the meta fields (title, author, …) to the returned fields, exluding the <attachment_field_name> field itself and including all the other attributes declared before it. For that reason you may want to declare it as the latest attribute.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/flex/active_model/attachment.rb', line 14 def (*args) name = args.first.is_a?(Symbol) ? args.shift : :attachment props = {:properties => { 'type' => 'attachment', 'fields' => { name.to_s => { 'store' => 'yes', 'term_vector' => 'with_positions_offsets' }, 'title' => { 'store' => 'yes' }, 'author' => { 'store' => 'yes' }, 'name' => { 'store' => 'yes' }, 'content_type' => { 'store' => 'yes' }, 'date' => { 'store' => 'yes' }, 'keywords' => { 'store' => 'yes' } } } } props.extend(Struct::Mergeable).deep_merge! args.first if args.first.is_a?(Hash) scope :"#{name}_scope", fields("#{name}.title", "#{name}.author", "#{name}.name", "#{name}.content_type", "#{name}.date", "#{name}.keywords", *attributes.keys) attribute name, props end |