Sha256: 69c632102cf9c5758d2b618eb8a73727adcb738c8e28561b0030040fbfb6a921

Contents?: true

Size: 1.04 KB

Versions: 19

Compression:

Stored size: 1.04 KB

Contents

module ForestLiana::Collection
  extend ActiveSupport::Concern

  module ClassMethods
    attr_accessor :collection_name
    attr_accessor :is_read_only
    attr_accessor :is_searchable

    def collection(name, opts = {})
      self.collection_name = name.to_s
      self.is_read_only = opts[:read_only] || false
      self.is_searchable = opts[:is_searchable] || true
    end

    def action(name, opts = {})
      opts[:name] = name
      model.actions << ForestLiana::Model::Action.new(opts)
    end

    def field(name, opts)
      model.fields << opts.merge({ field: name })
    end

    private

    def model
      collection = ForestLiana.apimap.find do |x|
        x.name.to_s == self.collection_name.try(:to_s)
      end

      if collection.blank?
        collection = ForestLiana::Model::Collection.new({
          name: self.collection_name.to_s,
          is_read_only: self.is_read_only,
          is_searchable: self.is_searchable,
          fields: []
        })

        ForestLiana.apimap << collection
      end

      collection
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
forest_liana-1.3.18 lib/forest_liana/collection.rb
forest_liana-1.3.17 lib/forest_liana/collection.rb
forest_liana-1.3.16 lib/forest_liana/collection.rb
forest_liana-1.3.15 lib/forest_liana/collection.rb
forest_liana-1.3.14 lib/forest_liana/collection.rb
forest_liana-1.3.13 lib/forest_liana/collection.rb
forest_liana-1.3.12 lib/forest_liana/collection.rb
forest_liana-1.3.11 lib/forest_liana/collection.rb
forest_liana-1.3.10 lib/forest_liana/collection.rb
forest_liana-1.3.9 lib/forest_liana/collection.rb
forest_liana-1.3.8 lib/forest_liana/collection.rb
forest_liana-1.3.7 lib/forest_liana/collection.rb
forest_liana-1.3.6 lib/forest_liana/collection.rb
forest_liana-1.3.5 lib/forest_liana/collection.rb
forest_liana-1.3.4 lib/forest_liana/collection.rb
forest_liana-1.3.3 lib/forest_liana/collection.rb
forest_liana-1.3.2 lib/forest_liana/collection.rb
forest_liana-1.3.1 lib/forest_liana/collection.rb
forest_liana-1.3.0 lib/forest_liana/collection.rb