Class: Pigeon::ChannelAttribute
- Inherits:
-
NestedAttribute
- Object
- NestedAttribute
- Pigeon::ChannelAttribute
- Extended by:
- NestedScopes
- Defined in:
- app/models/pigeon/channel_attribute.rb
Instance Attribute Summary collapse
-
#default_value ⇒ Object
readonly
Returns the value of attribute default_value.
-
#humanized_name ⇒ Object
readonly
Returns the value of attribute humanized_name.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#scope ⇒ Object
writeonly
Sets the attribute scope.
-
#tooltip ⇒ Object
readonly
Returns the value of attribute tooltip.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#user_editable ⇒ Object
readonly
Returns the value of attribute user_editable.
Attributes inherited from NestedAttribute
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, type, options = {}) ⇒ ChannelAttribute
constructor
A new instance of ChannelAttribute.
Methods included from NestedScopes
find_attr_recursive, find_attr_ref_recursive, fold_scoped_name
Methods inherited from NestedAttribute
Constructor Details
#initialize(name, type, options = {}) ⇒ ChannelAttribute
Returns a new instance of ChannelAttribute.
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, = {}) raise ArgumentError, "name cannot be blank (scope was '#{[:scope]}')" unless name.present? raise ArgumentError, "invalid type #{type}" unless self.class.valid_type?(type) @name = name @type = type.to_sym = .with_indifferent_access @scope = .delete(:scope) @default_value = ['default_value'] || ['value'] @humanized_name = ['humanized_name'] || ['display'] @label = ['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 = ['tooltip'] @user_editable = ['user'].nil? ? true : ['user'] @options = ['options'] || [] end |
Instance Attribute Details
#default_value ⇒ Object (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_name ⇒ Object (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 |
#label ⇒ Object (readonly)
Returns the value of attribute label.
3 4 5 |
# File 'app/models/pigeon/channel_attribute.rb', line 3 def label @label end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'app/models/pigeon/channel_attribute.rb', line 3 def @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 |
#tooltip ⇒ Object (readonly)
Returns the value of attribute tooltip.
3 4 5 |
# File 'app/models/pigeon/channel_attribute.rb', line 3 def tooltip @tooltip end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'app/models/pigeon/channel_attribute.rb', line 3 def type @type end |
#user_editable ⇒ Object (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 |