Module: ForestLiana::Collection::ClassMethods
- Defined in:
- lib/forest_liana/collection.rb
Instance Attribute Summary collapse
-
#active_record_class ⇒ Object
writeonly
Sets the attribute active_record_class.
-
#collection_name ⇒ Object
Returns the value of attribute collection_name.
-
#is_read_only ⇒ Object
Returns the value of attribute is_read_only.
-
#is_searchable ⇒ Object
Returns the value of attribute is_searchable.
Instance Method Summary collapse
- #action(name, opts = {}) ⇒ Object
- #belongs_to(name, opts, &block) ⇒ Object
- #collection(collection_name, opts = {}) ⇒ Object
- #field(name, opts, &block) ⇒ Object
- #has_many(name, opts, &block) ⇒ Object
- #segment(name, opts = {}, &block) ⇒ Object
Instance Attribute Details
#active_record_class=(value) ⇒ Object
Sets the attribute active_record_class
5 6 7 |
# File 'lib/forest_liana/collection.rb', line 5 def active_record_class=(value) @active_record_class = value end |
#collection_name ⇒ Object
Returns the value of attribute collection_name.
6 7 8 |
# File 'lib/forest_liana/collection.rb', line 6 def collection_name @collection_name end |
#is_read_only ⇒ Object
Returns the value of attribute is_read_only.
7 8 9 |
# File 'lib/forest_liana/collection.rb', line 7 def is_read_only @is_read_only end |
#is_searchable ⇒ Object
Returns the value of attribute is_searchable.
8 9 10 |
# File 'lib/forest_liana/collection.rb', line 8 def is_searchable @is_searchable end |
Instance Method Details
#action(name, opts = {}) ⇒ Object
16 17 18 19 20 |
# File 'lib/forest_liana/collection.rb', line 16 def action(name, opts = {}) opts[:id] = "#{self.collection_name.to_s}.#{name}" opts[:name] = name model.actions << ForestLiana::Model::Action.new(opts) end |
#belongs_to(name, opts, &block) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/forest_liana/collection.rb', line 65 def belongs_to(name, opts, &block) model.fields << opts.merge({ field: name, :'is-searchable' => false, type: 'String' }) if serializer_name && ForestLiana::UserSpace.const_defined?( serializer_name) ForestLiana::UserSpace.const_get(serializer_name).class_eval do has_one(name, name: name, include_data: true, &block) end end end |
#collection(collection_name, opts = {}) ⇒ Object
10 11 12 13 14 |
# File 'lib/forest_liana/collection.rb', line 10 def collection(collection_name, opts = {}) self.collection_name = collection_name.to_s self.is_read_only = opts[:read_only] || false self.is_searchable = opts[:is_searchable] || false end |
#field(name, opts, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/forest_liana/collection.rb', line 28 def field(name, opts, &block) opts[:read_only] = true unless opts.has_key?(:read_only) opts[:is_searchable] = false unless opts.has_key?(:is_searchable) opts[:read_only] = false if opts.has_key?(:set) opts[:is_searchable] = true if opts.has_key?(:search) model.fields << opts.merge({ field: name, :'is-read-only' => opts[:read_only], :'is-searchable' => opts['is_searchable'], :'is-virtual' => true }) if serializer_name && ForestLiana::UserSpace.const_defined?( serializer_name) ForestLiana::UserSpace.const_get(serializer_name).class_eval do attribute(name, &block) end end end |
#has_many(name, opts, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/forest_liana/collection.rb', line 50 def has_many(name, opts, &block) model.fields << opts.merge({ field: name, :'is-searchable' => false, type: ['String'] }) if serializer_name && ForestLiana::UserSpace.const_defined?( serializer_name) ForestLiana::UserSpace.const_get(serializer_name).class_eval do has_many(name, name: name) end end end |
#segment(name, opts = {}, &block) ⇒ Object
22 23 24 25 26 |
# File 'lib/forest_liana/collection.rb', line 22 def segment(name, opts = {}, &block) opts[:id] = "#{self.collection_name.to_s}.#{name}" opts[:name] = name model.segments << ForestLiana::Model::Segment.new(opts, &block) end |