Sha256: 1adbdf908d5d4fecd0f81db01f1f5458ba8df7236bb5e708ef9abd15341079f9

Contents?: true

Size: 1.28 KB

Versions: 8

Compression:

Stored size: 1.28 KB

Contents

module Faalis
  module Generators
    class Relation < String
      attr_accessor :to

      def initialize(value, to, options = "")
        super(value)
        @options = options
        @to = to
      end

      def resource_name
        to.split("/").last
      end

      def to
        result = "'"
        if options.include? "parents"
          field_parents.each do |parent|
            result = "#{result}/#{parent}/' + $scope.#{parent}_id + '"
          end
          result = "#{result}/"
        end
        "#{result}#{@to}'"
      end

      def options
        unless @options.empty?
          Hash[@options.split(',').map {|pair| pair.strip.split(':').map(&:strip) }]
        else
          {}
        end
      end

      def field_parents
        if options.include? "parents"
          options["parents"].split(";")
        else
          []
        end
      end

      def restangular
        result = "API"
        if options.include? "parents"
          field_parents.each do |parent|
            result = "#{result}.one('#{parent}', #{}_id)"
          end
        end
        to.split("/").each do |resource|
          result = "#{result}.all(\"#{resource}\")"
        end
        result
      end

      def get_list
        "#{restangular}.getList()"
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
faalis-2.0.0.rc2 lib/faalis/generators/fields/#relation.rb#
faalis-1.0.0.alpha3 lib/faalis/generators/fields/#relation.rb#
faalis-1.0.0.alpha1 lib/faalis/generators/fields/#relation.rb#
faalis-0.26.0 lib/faalis/generators/fields/#relation.rb#
faalis-0.25.1 lib/faalis/generators/fields/#relation.rb#
faalis-0.24.3 lib/faalis/generators/fields/#relation.rb#
faalis-0.24.2 lib/faalis/generators/fields/#relation.rb#
faalis-0.19.0 lib/faalis/generators/fields/relation.rb