Class: Refinery::Generators::GeneratedAttribute

Inherits:
Rails::Generators::GeneratedAttribute
  • Object
show all
Defined in:
lib/refinery/generators/generated_attribute.rb

Constant Summary collapse

REFINERY_TYPES =
%w(image resource radio select checkbox)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type = nil, index_type = false, attr_options = {}) ⇒ GeneratedAttribute

Returns a new instance of GeneratedAttribute.



27
28
29
30
31
# File 'lib/refinery/generators/generated_attribute.rb', line 27

def initialize(name, type=nil, index_type=false, attr_options={})
  super
  self.refinery_type  = type
  self.type           = refinerize_type(type)
end

Instance Attribute Details

#refinery_typeObject

Returns the value of attribute refinery_type.



8
9
10
# File 'lib/refinery/generators/generated_attribute.rb', line 8

def refinery_type
  @refinery_type
end

Class Method Details

.parse(column_definition) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/refinery/generators/generated_attribute.rb', line 11

def parse(column_definition)
  name, type, index_type = column_definition.split(":")

  # Handle Refinery's custom types before Rails validates them
  if type && REFINERY_TYPES.include?(type)
    new(name, type.to_sym, index_type)
  else
    super
  end
end

.reference?(type) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/refinery/generators/generated_attribute.rb', line 22

def reference?(type)
  [:references, :belongs_to, :image, :resource].include? type
end

Instance Method Details

#reference?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/refinery/generators/generated_attribute.rb', line 33

def reference?
  self.class.reference?(refinery_type)
end