Module: Houston::Props

Extended by:
ActiveSupport::Concern
Included in:
Authorization, Project, Team, User
Defined in:
app/concerns/houston/props.rb

Defined Under Namespace

Modules: ClassMethods Classes: PropsIndexer

Constant Summary collapse

VALID_PROP_NAME =
/\A[a-z0-9]+(?:\.[a-z0-9_\-]+)+\Z/i.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.valid_prop_name!(prop_name) ⇒ Object

Raises:

  • (ArgumentError)


7
8
9
10
# File 'app/concerns/houston/props.rb', line 7

def self.valid_prop_name!(prop_name)
  return if valid_prop_name?(prop_name)
  raise ArgumentError, "#{prop_name.inspect} can only contain word-characters, hyphens, and must contain at least one period"
end

.valid_prop_name?(prop_name) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'app/concerns/houston/props.rb', line 12

def self.valid_prop_name?(prop_name)
  prop_name =~ VALID_PROP_NAME
end

Instance Method Details

#get_prop(prop_name) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/concerns/houston/props.rb', line 41

def get_prop(prop_name)
  Houston::Props.valid_prop_name!(prop_name)
  value = props[prop_name]

  if !value && block_given?
    value = yield self
    if value
      update_prop! prop_name, value
    else
      Rails.logger.info "\e[34mUnable to identify \e[1m#{prop_name}\e[0;34m for #{inspect}\e[0m"
    end
  end

  value
end

#propsObject



65
66
67
# File 'app/concerns/houston/props.rb', line 65

def props
  PropsIndexer.new(self, super)
end

#update_prop!(prop_name, value) ⇒ Object



57
58
59
# File 'app/concerns/houston/props.rb', line 57

def update_prop!(prop_name, value)
  update_props!(prop_name => value)
end

#update_props!(new_props) ⇒ Object



61
62
63
# File 'app/concerns/houston/props.rb', line 61

def update_props!(new_props)
  update_column :props, props.merge!(new_props)
end