Class: Pigeon::ChannelAttribute

Inherits:
NestedAttribute show all
Extended by:
NestedScopes
Defined in:
app/models/pigeon/channel_attribute.rb

Instance Attribute Summary collapse

Attributes inherited from NestedAttribute

#name, #scope

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NestedScopes

find_attr_recursive, find_attr_ref_recursive, fold_scoped_name

Methods inherited from NestedAttribute

#scoped_name

Constructor Details

#initialize(name, type, options = {}) ⇒ ChannelAttribute

Returns a new instance of ChannelAttribute.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/pigeon/channel_attribute.rb', line 6

def initialize(name, type, options = {})
  raise ArgumentError, "name cannot be blank (scope was '#{options[:scope]}')" unless name.present?
  raise ArgumentError, "invalid type #{type}" unless self.class.valid_type?(type)

  @name = name
  @type = type.to_sym
  options = options.with_indifferent_access

  @scope = options.delete(:scope)

  @default_value = options['default_value'] || options['value']
  @humanized_name = options['humanized_name'] || options['display']
  @label = options['label']
  if @label.present?
    @humanized_name ||= @label
  elsif @humanized_name.present?
    @label ||= @humanized_name
  else
    @label = name.to_s.humanize
    @humanized_name = @label
  end
  @tooltip = options['tooltip']
  @user_editable = options['user'].nil? ? true : options['user']
  @options = options['options'] || []
end

Instance Attribute Details

#default_valueObject (readonly)

Returns the value of attribute default_value.



3
4
5
# File 'app/models/pigeon/channel_attribute.rb', line 3

def default_value
  @default_value
end

#humanized_nameObject (readonly)

Returns the value of attribute humanized_name.



3
4
5
# File 'app/models/pigeon/channel_attribute.rb', line 3

def humanized_name
  @humanized_name
end

#labelObject (readonly)

Returns the value of attribute label.



3
4
5
# File 'app/models/pigeon/channel_attribute.rb', line 3

def label
  @label
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'app/models/pigeon/channel_attribute.rb', line 3

def options
  @options
end

#scope=(value) ⇒ Object (writeonly)

Sets the attribute scope



4
5
6
# File 'app/models/pigeon/channel_attribute.rb', line 4

def scope=(value)
  @scope = value
end

#tooltipObject (readonly)

Returns the value of attribute tooltip.



3
4
5
# File 'app/models/pigeon/channel_attribute.rb', line 3

def tooltip
  @tooltip
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'app/models/pigeon/channel_attribute.rb', line 3

def type
  @type
end

#user_editableObject (readonly)

Returns the value of attribute user_editable.



3
4
5
# File 'app/models/pigeon/channel_attribute.rb', line 3

def user_editable
  @user_editable
end

Class Method Details

.build_default(name, hint_value = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/pigeon/channel_attribute.rb', line 36

def self.build_default(name, hint_value = nil)
  type = case hint_value
         when Fixnum
           :integer
         when FalseClass, TrueClass
           :boolean
         else
           :string
         end
  name, scope = build_scope_recursive(name)
  new name, type, value: hint_value, scope: scope
end

.valid_type?(type) ⇒ Boolean



32
33
34
# File 'app/models/pigeon/channel_attribute.rb', line 32

def self.valid_type?(type)
  %w(string boolean password enum multi integer timezone hidden).include?(type.to_s)
end