Module: Shoes::Common::Style::StyleWith

Defined in:
shoes-core/lib/shoes/common/style.rb

Instance Method Summary collapse

Instance Method Details

#define_reader_methodsObject



96
97
98
99
100
101
102
103
104
105
106
# File 'shoes-core/lib/shoes/common/style.rb', line 96

def define_reader_methods
  needs_readers = @supported_styles.reject do |style|
    method_defined?(style)
  end

  needs_readers.map(&:to_sym).each do |style|
    define_method style do
      @style[style]
    end
  end
end

#define_writer_methodsObject



108
109
110
111
112
113
114
115
116
117
118
# File 'shoes-core/lib/shoes/common/style.rb', line 108

def define_writer_methods
  needs_writers = @supported_styles.reject do |style|
    method_defined?("#{style}=")
  end

  needs_writers.map(&:to_sym).each do |style_key|
    define_method "#{style_key}=" do |new_style|
      send("style", style_key.to_sym => new_style)
    end
  end
end

#style_with(*styles) ⇒ Object



72
73
74
75
76
77
78
# File 'shoes-core/lib/shoes/common/style.rb', line 72

def style_with(*styles)
  @supported_styles = []

  unpack_style_groups(styles)
  define_reader_methods
  define_writer_methods
end

#unpack_style_groups(styles) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'shoes-core/lib/shoes/common/style.rb', line 80

def unpack_style_groups(styles)
  styles.each do |style|
    if STYLE_GROUPS[style]
      STYLE_GROUPS[style].each { |group_style| support_style group_style }
    else
      support_style style
    end
  end

  supported_styles = @supported_styles

  define_method("supported_styles") do
    supported_styles
  end
end