Class: Appfuel::Repository::Expr

Inherits:
Object
  • Object
show all
Defined in:
lib/appfuel/storage/repository/expr.rb

Overview

Domain expressions are used mostly by the criteria to describe filter conditions. The class represents a basic expression like “id = 6”, the problem with this expression is that “id” is relative to the domain represented by the criteria. In order to convert that expression to a storage expression for a db, that expression must be fully qualified in the form of “features.feature_name.domain.id = 6” so that the mapper can correctly map to database attributes. This class provides the necessary interfaces to allow a criteria to qualify all of its relative expressions. It also allows fully qualifed expressions to be used.

Direct Known Subclasses

OrderExpr

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain_attr, op, value) ⇒ Expr

Returns a new instance of Expr.



15
16
17
18
19
20
21
22
# File 'lib/appfuel/storage/repository/expr.rb', line 15

def initialize(domain_attr, op, value)
  @attr_list = parse_domain_attr(domain_attr)
  @op        = op.to_s.strip
  @value     = value

  fail "op can not be empty" if @op.empty?
  fail "attr_list can not be empty" if @attr_list.empty?
end

Instance Attribute Details

#attr_listObject (readonly)

Returns the value of attribute attr_list.



13
14
15
# File 'lib/appfuel/storage/repository/expr.rb', line 13

def attr_list
  @attr_list
end

#domain_attrObject (readonly)

Returns the value of attribute domain_attr.



13
14
15
# File 'lib/appfuel/storage/repository/expr.rb', line 13

def domain_attr
  @domain_attr
end

#domain_basenameObject (readonly)

Returns the value of attribute domain_basename.



13
14
15
# File 'lib/appfuel/storage/repository/expr.rb', line 13

def domain_basename
  @domain_basename
end

#featureObject (readonly)

Returns the value of attribute feature.



13
14
15
# File 'lib/appfuel/storage/repository/expr.rb', line 13

def feature
  @feature
end

#opObject (readonly)

Returns the value of attribute op.



13
14
15
# File 'lib/appfuel/storage/repository/expr.rb', line 13

def op
  @op
end

#valueObject (readonly)

Returns the value of attribute value.



13
14
15
# File 'lib/appfuel/storage/repository/expr.rb', line 13

def value
  @value
end

Instance Method Details

#conjunction?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/appfuel/storage/repository/expr.rb', line 44

def conjunction?
  false
end

#domain_nameObject



62
63
64
# File 'lib/appfuel/storage/repository/expr.rb', line 62

def domain_name
  "#{feature}.#{domain_basename}"
end

#global?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/appfuel/storage/repository/expr.rb', line 40

def global?
  attr_list[0] == 'global'
end

#qualified?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/appfuel/storage/repository/expr.rb', line 48

def qualified?
  attr_list[0] == 'global' || attr_list[0] == 'features'
end

#qualify_feature(feature, domain) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/appfuel/storage/repository/expr.rb', line 24

def qualify_feature(feature, domain)
  fail "this expr is already qualified" if qualified?

  attr_list.unshift(domain)
  attr_list.unshift(feature)
  attr_list.unshift('features')
  self
end

#qualify_global(domain) ⇒ Object



33
34
35
36
37
38
# File 'lib/appfuel/storage/repository/expr.rb', line 33

def qualify_global(domain)
  fail "this expr is already qualified" if qualified?
  attr_list.unshift(domain)
  attr_list.unshift('global')
  self
end

#to_sObject



72
73
74
# File 'lib/appfuel/storage/repository/expr.rb', line 72

def to_s
  "#{attr_list.join('.')} #{op} #{value}"
end

#validate_as_fully_qualifiedObject



76
77
78
79
80
81
# File 'lib/appfuel/storage/repository/expr.rb', line 76

def validate_as_fully_qualified
  unless qualified?
    fail "expr (#{to_s}) is not fully qualified, mapping will not work"
  end
  true
end