Class: Cubicle::Member
- Inherits:
-
Object
- Object
- Cubicle::Member
- Defined in:
- lib/cubicle/member.rb
Instance Attribute Summary collapse
-
#alias_list ⇒ Object
Returns the value of attribute alias_list.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#expression ⇒ Object
Returns the value of attribute expression.
-
#expression_type ⇒ Object
Returns the value of attribute expression_type.
-
#field_name ⇒ Object
Returns the value of attribute field_name.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options(*args) ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #included_in?(list_of_member_names) ⇒ Boolean
-
#initialize(*args) ⇒ Member
constructor
A new instance of Member.
- #matches(member_name) ⇒ Object
- #to_js_keys ⇒ Object
- #to_js_value ⇒ Object
Constructor Details
#initialize(*args) ⇒ Member
Returns a new instance of Member.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cubicle/member.rb', line 12 def initialize(*args) opts = args. @name = args.shift.to_sym if args[0].is_a?(String) or args[0].is_a?(Symbol) self. = (opts || {}).symbolize_keys if @expression = (:field_name) @expression_type = :field_name @field_name = @expression elsif @expression = (:expression) @expression_type = :javascript else @expression = @name @field_name = @name @expression_type = :field_name end member_alias = (:alias) if (member_alias) member_alias = [member_alias] unless member_alias.is_a?(Array) @alias_list = member_alias.map{|a|a.to_s} end @condition = :condition_expression,:condition end |
Instance Attribute Details
#alias_list ⇒ Object
Returns the value of attribute alias_list.
4 5 6 |
# File 'lib/cubicle/member.rb', line 4 def alias_list @alias_list end |
#condition ⇒ Object
Returns the value of attribute condition.
4 5 6 |
# File 'lib/cubicle/member.rb', line 4 def condition @condition end |
#expression ⇒ Object
Returns the value of attribute expression.
4 5 6 |
# File 'lib/cubicle/member.rb', line 4 def expression @expression end |
#expression_type ⇒ Object
Returns the value of attribute expression_type.
4 5 6 |
# File 'lib/cubicle/member.rb', line 4 def expression_type @expression_type end |
#field_name ⇒ Object
Returns the value of attribute field_name.
4 5 6 |
# File 'lib/cubicle/member.rb', line 4 def field_name @field_name end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/cubicle/member.rb', line 4 def name @name end |
#options(*args) ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/cubicle/member.rb', line 4 def @options end |
Instance Method Details
#included_in?(list_of_member_names) ⇒ Boolean
49 50 51 52 53 54 |
# File 'lib/cubicle/member.rb', line 49 def included_in?(list_of_member_names) list_of_member_names.each do |member_name| return true if matches(member_name) end false end |
#matches(member_name) ⇒ Object
45 46 47 |
# File 'lib/cubicle/member.rb', line 45 def matches(member_name) return name.to_s == member_name.to_s || (@alias_list||=[]).include?(member_name.to_s) end |
#to_js_keys ⇒ Object
56 57 58 |
# File 'lib/cubicle/member.rb', line 56 def to_js_keys ["#{name}:#{to_js_value}"] end |
#to_js_value ⇒ Object
65 66 67 |
# File 'lib/cubicle/member.rb', line 65 def to_js_value condition.blank? ? expression : "(#{condition}) ? (#{expression}) : null" end |