Class: Faalis::Generators::Relation

Inherits:
String
  • Object
show all
Defined in:
lib/faalis/generators/fields/relation.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Relation) initialize(value, to, options = "")

Returns a new instance of Relation



6
7
8
9
10
# File 'lib/faalis/generators/fields/relation.rb', line 6

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

Instance Attribute Details

- (Object) to

Returns the value of attribute to



4
5
6
# File 'lib/faalis/generators/fields/relation.rb', line 4

def to
  @to
end

Instance Method Details

- (Object) field_parents



35
36
37
38
39
40
41
# File 'lib/faalis/generators/fields/relation.rb', line 35

def field_parents
  if options.include? "parents"
    options["parents"]
  else
    []
  end
end

- (Object) get_list



56
57
58
# File 'lib/faalis/generators/fields/relation.rb', line 56

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

- (Object) options



27
28
29
30
31
32
33
# File 'lib/faalis/generators/fields/relation.rb', line 27

def options
  unless @options.empty?
    @options
  else
    {}
  end
end

- (Object) resource_name



12
13
14
# File 'lib/faalis/generators/fields/relation.rb', line 12

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

- (Object) restangular



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/faalis/generators/fields/relation.rb', line 43

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